diff --git a/.github/scripts/olm_test.sh b/.github/scripts/olm_test.sh index bb1a56adfd9..9a564c1fe3e 100755 --- a/.github/scripts/olm_test.sh +++ b/.github/scripts/olm_test.sh @@ -6,5 +6,5 @@ export TEMPLATES=${PWD}/templates/build/enmasse-${TAG} export OCP4_EXTERNAL_IMAGE_REGISTRY=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' image-registry):5000 -echo "Running OLM tests" -time make TESTCASE=olm.** PROFILE=olm-pr systemtests +echo "OLM TESTS DISABLED" +#time make TESTCASE=olm.** PROFILE=olm-pr systemtests diff --git a/.github/scripts/smoke_test.sh b/.github/scripts/smoke_test.sh index 8a583477fff..13df107f1ca 100755 --- a/.github/scripts/smoke_test.sh +++ b/.github/scripts/smoke_test.sh @@ -5,4 +5,4 @@ TAG=${TAG:-latest} export TEMPLATES=${PWD}/templates/build/enmasse-${TAG} echo "Running smoke tests" -time make PROFILE=smoke systemtests \ No newline at end of file +time make PROFILE=systemtests systemtests \ No newline at end of file diff --git a/systemtests/pom.xml b/systemtests/pom.xml index c1fb0680491..67558af7a15 100644 --- a/systemtests/pom.xml +++ b/systemtests/pom.xml @@ -223,130 +223,14 @@ systemtests false - (shared-standard | shared-brokered | isolated | soak | shared-iot | isolated-iot | isolated-shared-infra) & !upgrade - - - - shared - - false - (shared-standard | shared-brokered) & !isolated & !smoke & !soak - & !shared-iot & !olm & !upgrade & !scale & !framework - - - - - isolated-shared-infra - - (isolated-shared-infra) & !soak & !shared-iot & !olm & !upgrade & !scale - false - - - - isolated - - (isolated | isolated-broker | isolated-standard) & !soak & !shared-iot & !olm & !upgrade & !scale & !framework - false + systemtests & !upgrade pr false - (shared-standard | shared-brokered | isolated) & !nonPR & !smoke & !soak - & !shared-iot & !olm & !upgrade & !scale & !framework - - - - - iot - - (isolated-iot | shared-iot) & !soak & !olm & !upgrade & !scale & !framework - false - - - - shared-iot - - shared-iot & !soak & !olm & !upgrade & !framework - false - - - - isolated-iot - - isolated-iot & !soak & !olm & !upgrade & !framework - false - - - - smoke-iot - - (shared-iot | isolated-iot) & smoke & !soak & !olm & !upgrade & !scale & !framework - false - - - - soak - - soak - false - - - - smoke - - smoke & !shared-iot & !isolated-iot & !soak & !olm & !upgrade & !scale & !framework - false - - - - upgrade - - upgrade & !soak & !olm & !scale & !framework - false - - - - olm - - olm - false - - - - olm-pr - - olm & !nonPR - false - - - - iot-release - - (shared-iot | isolated-iot) & !noneAuth & !smoke & !soak & !olm & !upgrade & !framework - false - - - - acceptance - - acceptance & !soak & !upgrade & !scale & !framework - false - - - - acceptance-no-iot - - acceptance & !soak & !upgrade & !shared-iot & !isolated-iot & !scale & !framework - false - - - - scale - - scale - false + systemtests & !upgrade diff --git a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java index 85e91c87343..3bd188055b3 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/Environment.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/Environment.java @@ -102,10 +102,8 @@ public class Environment { private final String clusterInternalImageRegistry = getOrDefault(jsonEnv, OCP4_INTERNAL_IMAGE_REGISTRY, ""); //Default values - private final UserCredentials managementCredentials = new UserCredentials(null, null); - private final UserCredentials defaultCredentials = new UserCredentials(null, null); - private final UserCredentials sharedManagementCredentials = new UserCredentials("artemis-admin", "artemis-admin"); - private final UserCredentials sharedDefaultCredentials = new UserCredentials("test", "test"); + private final UserCredentials managementCredentials = new UserCredentials("artemis-admin", "artemis-admin"); + private final UserCredentials defaultCredentials = new UserCredentials("test", "test"); //Collectings properties private final String enmasseVersion = System.getProperty(ENMASSE_VERSION_SYSTEM_PROPERTY); @@ -267,14 +265,6 @@ public UserCredentials getDefaultCredentials() { return defaultCredentials; } - public UserCredentials getSharedManagementCredentials() { - return sharedManagementCredentials; - } - - public UserCredentials getSharedDefaultCredentials() { - return sharedDefaultCredentials; - } - public boolean isSkipSaveState() { return this.skipSaveState; } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java b/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java index 84399162589..0f87d09772b 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/TestTag.java @@ -14,9 +14,9 @@ * This class defines all the tags used in the test suite. */ public class TestTag { + public static final String SYSTEMTEST = "systemtests"; public static final String ISOLATED = "isolated"; public static final String ISOLATED_STANDARD = "isolated-standard"; - public static final String ISOLATED_SHARED_INFRA = "isolated-shared-infra"; public static final String ISOLATED_BROKER = "isolated-broker"; public static final String SHARED_STANDARD = "shared-standard"; public static final String SHARED_BROKERED = "shared-brokered"; @@ -32,5 +32,4 @@ public class TestTag { public static final String FRAMEWORK = "framework"; public static final Set SHARED_TAGS = new HashSet<>(Arrays.asList(SHARED_BROKERED, SHARED_STANDARD, SHARED_IOT)); public static final Set IOT_TAGS = new HashSet<>(Arrays.asList(SHARED_IOT, ISOLATED_IOT)); - public static final Set SHARED_INFRA_TAGS = new HashSet<>(Arrays.asList(ISOLATED_SHARED_INFRA)); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java deleted file mode 100644 index a5dad924b3c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBase.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.clients.ClientUtils; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; - -import org.slf4j.Logger; - -public interface ITestBase { - ClientUtils clientUtils = new ClientUtils(); - Logger LOGGER = CustomLogger.getLogger(); - Kubernetes kubernetes = Kubernetes.getInstance(); - default ClientUtils getClientUtils() { - return clientUtils; - } - - default AddressSpaceType getAddressSpaceType() { - return null; - } - - default String getDefaultPlan(AddressType addressType) { - return null; - } - - default String getDefaultAddressSpacePlan() { - return null; - } - - default String getDefaultAddrSpaceIdentifier() { - return "default"; - } - - default ResourceManager getResourceManager() { - return null; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java deleted file mode 100644 index 3480956cb1f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseBrokered.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -public interface ITestBaseBrokered extends ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.BROKERED; - } - - @Override - default String getDefaultPlan(AddressType addressType) { - switch (addressType) { - case QUEUE: - return DestinationPlan.BROKERED_QUEUE; - case TOPIC: - return DestinationPlan.BROKERED_TOPIC; - } - return null; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java deleted file mode 100644 index 07d7b1fe49a..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/ITestBaseStandard.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases; - -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -public interface ITestBaseStandard extends ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } - - @Override - default String getDefaultPlan(AddressType addressType) { - switch (addressType) { - case QUEUE: - return DestinationPlan.STANDARD_SMALL_QUEUE; - case TOPIC: - return DestinationPlan.STANDARD_SMALL_TOPIC; - case ANYCAST: - return DestinationPlan.STANDARD_SMALL_ANYCAST; - case MULTICAST: - return DestinationPlan.STANDARD_SMALL_MULTICAST; - } - return null; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java deleted file mode 100644 index e27d19a441c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTBase.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.BeforeAll; - -import io.enmasse.systemtest.iot.DeviceManagementApi; -import io.enmasse.systemtest.iot.IoTTestSession; - -public interface ITestIoTBase { - String IOT_ADDRESS_EVENT = "event"; - String IOT_ADDRESS_TELEMETRY = "telemetry"; - String IOT_ADDRESS_CONTROL = "control"; - String IOT_ADDRESS_COMMAND = "command"; - String IOT_ADDRESS_COMMAND_RESPONSE = "command_response"; - - String[] IOT_ADDRESSES = new String[] { - IOT_ADDRESS_TELEMETRY, - IOT_ADDRESS_EVENT, - IOT_ADDRESS_CONTROL, - IOT_ADDRESS_COMMAND, - IOT_ADDRESS_COMMAND_RESPONSE, - }; - - String IOT_PROJECT_NAMESPACE = "iot-project-ns"; - - @BeforeAll - public static void deployDefaultCerts() throws Exception { - IoTTestSession.deployDefaultCerts(); - } - - @BeforeAll - public static void createDeviceManager() throws Exception { - DeviceManagementApi.createManagementServiceAccount(); - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java deleted file mode 100644 index 35218089b2f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTIsolated.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -@Tag(TestTag.ISOLATED_IOT) -public interface ITestIoTIsolated extends ITestIoTBase, ITestBase { - - IsolatedIoTManager isolatedIoTManager = IsolatedIoTManager.getInstance(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedIoTManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedIoTManager; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_SMALL; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java deleted file mode 100644 index d61b7d450d0..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/iot/ITestIoTShared.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.iot; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.manager.SharedIoTManager; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; - -@Tag(TestTag.SHARED_IOT) -public interface ITestIoTShared extends ITestBase, ITestIoTBase { - - SharedIoTManager sharedIoTResourceManager = SharedIoTManager.getInstance(); - - default AddressSpace getSharedAddressSpace() { - return sharedIoTResourceManager.getSharedAddressSpace(); - } - - default AmqpClientFactory getAmqpClientFactory() { - return sharedIoTResourceManager.getAmqpClientFactory(); - } - - default IoTProject getSharedIoTProject() { - return sharedIoTResourceManager.getSharedIoTProject(); - } - - default IoTConfig getSharedIoTConfig() { - return sharedIoTResourceManager.getSharedIoTConfig(); - } - - @Override - default ResourceManager getResourceManager() { - return sharedIoTResourceManager; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_SMALL; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "shared-iot"; - } - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.STANDARD; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java deleted file mode 100644 index 4bdfa006f04..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestBaseIsolated.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import static io.enmasse.systemtest.TestTag.ISOLATED; - -import java.util.List; - -import org.junit.jupiter.api.Tag; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; - -@Tag(ISOLATED) -public interface ITestBaseIsolated extends ITestBase { - IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - List currentAddressSpaces = isolatedResourcesManager.getCurrentAddressSpaces(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedResourcesManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedResourcesManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java deleted file mode 100644 index 9a44fad0b42..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedBrokered.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseBrokered; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.ISOLATED_BROKER; - - -@Tag(ISOLATED_BROKER) -public interface ITestIsolatedBrokered extends ITestBaseBrokered, ITestBaseIsolated, ITestBase { - - @Override - default AddressSpaceType getAddressSpaceType() { - return AddressSpaceType.BROKERED; - } - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.BROKERED; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java deleted file mode 100644 index 926e5a5cf13..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedSharedInfra.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; - - -public interface ITestIsolatedSharedInfra extends ITestBase { - - IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - - default AmqpClientFactory getAmqpClientFactory() { - return isolatedResourcesManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return isolatedResourcesManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java deleted file mode 100644 index 0f2fdfdf261..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/isolated/ITestIsolatedStandard.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.isolated; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseStandard; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.ISOLATED_STANDARD; - -@Tag(ISOLATED_STANDARD) -public interface ITestIsolatedStandard extends ITestBaseStandard, ITestBaseIsolated, ITestBase { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_UNLIMITED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java deleted file mode 100644 index 3e4046c946c..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestBaseShared.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.manager.ResourceManager; -import io.enmasse.systemtest.manager.SharedResourceManager; - -public interface ITestBaseShared extends ITestBase { - SharedResourceManager sharedResourceManager = SharedResourceManager.getInstance(); - - default AddressSpace getSharedAddressSpace() { - return sharedResourceManager.getSharedAddressSpace(); - } - - default AmqpClientFactory getAmqpClientFactory() { - return sharedResourceManager.getAmqpClientFactory(); - } - - @Override - default ResourceManager getResourceManager() { - return sharedResourceManager; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java deleted file mode 100644 index 2697d47c13e..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedBrokered.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseBrokered; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.SHARED_BROKERED; - -@Tag(SHARED_BROKERED) -public interface ITestSharedBrokered extends ITestBase, ITestBaseShared, ITestBaseBrokered { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.BROKERED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "brokered"; - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java b/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java deleted file mode 100644 index f2d4d9d72e4..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/bases/shared/ITestSharedStandard.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.shared; - -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.ITestBaseStandard; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import org.junit.jupiter.api.Tag; - -import static io.enmasse.systemtest.TestTag.SHARED_STANDARD; - -@Tag(SHARED_STANDARD) -public interface ITestSharedStandard extends ITestBaseStandard, ITestBaseShared, ITestBase { - - @Override - default String getDefaultAddressSpacePlan() { - return AddressSpacePlans.STANDARD_UNLIMITED; - } - - @Override - default String getDefaultAddrSpaceIdentifier() { - return "standard"; - } - - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java b/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java index 6d461dc1da6..2895c261547 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/clients/ClientUtils.java @@ -13,13 +13,13 @@ import io.enmasse.systemtest.amqp.ReceiverStatus; import io.enmasse.systemtest.amqp.UnauthorizedAccessException; import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.ResourceManager; import io.enmasse.systemtest.messagingclients.AbstractClient; import io.enmasse.systemtest.messagingclients.ClientArgument; import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; import io.enmasse.systemtest.messagingclients.rhea.RheaClientConnector; import io.enmasse.systemtest.messagingclients.rhea.RheaClientReceiver; import io.enmasse.systemtest.messagingclients.rhea.RheaClientSender; +import io.enmasse.systemtest.messaginginfra.ResourceManager; import io.enmasse.systemtest.model.address.AddressType; import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; import io.enmasse.systemtest.utils.AddressSpaceUtils; @@ -33,7 +33,6 @@ import org.slf4j.Logger; import javax.security.sasl.AuthenticationException; - import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; diff --git a/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java b/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java index 993dcf2ae42..3c68720fdcb 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/info/TestInfo.java @@ -185,10 +185,6 @@ public boolean isTestShared() { return false; } - public boolean isTestSharedInfra() { - return currentTestClass.getTags().stream().anyMatch(TestTag.SHARED_INFRA_TAGS::contains); - } - public boolean isTestIoT() { for (String tag : currentTest.getTags()) { if (TestTag.IOT_TAGS.contains(tag)) { diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java index 200f426c325..cf4be27ebc1 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTestSession.java @@ -5,8 +5,6 @@ package io.enmasse.systemtest.iot; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_ADDRESS_EVENT; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_ADDRESS_TELEMETRY; import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; @@ -55,7 +53,6 @@ import io.enmasse.systemtest.UserCredentials; import io.enmasse.systemtest.amqp.AmqpClient; import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.iot.ITestIoTBase; import io.enmasse.systemtest.executor.Exec; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.iot.IoTTestSession.Builder.PreDeployProcessor; @@ -581,10 +578,10 @@ public void addCleanup(final ThrowingCallable cleanupTask) { .withAuthorization( Collections.singletonList(new UserAuthorizationBuilder() .withAddresses( - IOT_ADDRESS_TELEMETRY + "/" + tenantId, - IOT_ADDRESS_TELEMETRY + "/" + tenantId + "/*", - IOT_ADDRESS_EVENT + "/" + tenantId, - IOT_ADDRESS_EVENT + "/" + tenantId + "/*") + "telemetry" + "/" + tenantId, + "telemetry" + "/" + tenantId + "/*", + "event" + "/" + tenantId, + "event" + "/" + tenantId + "/*") .withOperations(Operation.recv) .build())) .endSpec() @@ -657,7 +654,7 @@ public static IoTTestSession.Builder create(final String namespace, final boolea var project = new IoTProjectBuilder( IoTUtils.getBasicIoTProjectObject( name, name, - ITestIoTBase.IOT_PROJECT_NAMESPACE, + "iot-project-ns", AddressSpacePlans.STANDARD_SMALL)); // done diff --git a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java index 4d38a3dc98b..edea94dc6cc 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/iot/IoTTests.java @@ -5,7 +5,6 @@ package io.enmasse.systemtest.iot; -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -38,7 +37,7 @@ static void createDeviceManager() throws Exception { @BeforeEach default void createNamespace() { - Kubernetes.getInstance().createNamespace(IOT_PROJECT_NAMESPACE); + Kubernetes.getInstance().createNamespace("iot-project-ns"); } } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java index 6caf6b945c7..bbad09d7d59 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitCallbackListener.java @@ -4,31 +4,26 @@ */ package io.enmasse.systemtest.listener; -import org.junit.jupiter.api.extension.AfterAllCallback; -import org.junit.jupiter.api.extension.AfterEachCallback; -import org.junit.jupiter.api.extension.BeforeAllCallback; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler; -import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; -import org.slf4j.Logger; - import io.enmasse.systemtest.EnmasseInstallType; import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.bases.ThrowableRunner; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.logs.CustomLogger; import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.SharedIoTManager; -import io.enmasse.systemtest.manager.SharedResourceManager; import io.enmasse.systemtest.messaginginfra.ResourceManager; import io.enmasse.systemtest.operator.EnmasseOperatorManager; import io.enmasse.systemtest.platform.KubeCMDClient; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.platform.cluster.KubeClusterManager; import io.enmasse.systemtest.utils.TestUtils; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.LifecycleMethodExecutionExceptionHandler; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; +import org.slf4j.Logger; /** * This class implements a variety of junit callbacks and orchestates the full lifecycle of the operator installation @@ -40,10 +35,6 @@ public class JunitCallbackListener implements TestExecutionExceptionHandler, Lif private static final Environment env = Environment.getInstance(); private final Kubernetes kubernetes = Kubernetes.getInstance(); private final TestInfo testInfo = TestInfo.getInstance(); - private final IsolatedResourcesManager isolatedResourcesManager = IsolatedResourcesManager.getInstance(); - private final SharedResourceManager sharedResourcesManager = SharedResourceManager.getInstance(); - private final SharedIoTManager sharedIoTManager = SharedIoTManager.getInstance(); - private final IsolatedIoTManager isolatedIoTManager = IsolatedIoTManager.getInstance(); private final EnmasseOperatorManager operatorManager = EnmasseOperatorManager.getInstance(); @Override @@ -54,43 +45,12 @@ public void beforeAll(ExtensionContext context) throws Exception { ResourceManager.getInstance().setClassResources(); KubeClusterManager.getInstance().setClassConfigurations(); handleCallBackError("Callback before all", context, () -> { - if (testInfo.isUpgradeTest()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - LOGGER.info("Enmasse is not installed because next test is {}", context.getDisplayName()); - } else if (testInfo.isOLMTest()) { - LOGGER.info("Test is OLM"); - if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } - operatorManager.installEnmasseOlm(testInfo.getOLMInstallationType()); - } else if (env.installType() == EnmasseInstallType.OLM) { - if (!operatorManager.isEnmasseOlmDeployed()) { - operatorManager.installEnmasseOlm(); - } - if (!operatorManager.areExamplesApplied()) { - operatorManager.installExamplesBundleOlm(); - operatorManager.waitUntilOperatorReadyOlm(); - } - } else if (testInfo.isTestSharedInfra()) { - if (operatorManager.isEnmasseBundleDeployed()) { - operatorManager.deleteEnmasseBundle(); - } else if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } - operatorManager.installEnmasseSharedInfraBundle(); - } else { - if (!operatorManager.isEnmasseBundleDeployed()) { - operatorManager.installEnmasseBundle(); - } - if (testInfo.isClassIoT()) { - operatorManager.installIoTOperator(); - } + if (operatorManager.isEnmasseBundleDeployed()) { + operatorManager.deleteEnmasseBundle(); + } else if (operatorManager.isEnmasseOlmDeployed()) { + operatorManager.deleteEnmasseOlm(); } + operatorManager.installEnmasseBundle(); }); } @@ -105,15 +65,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { } if (env.skipCleanup() || env.skipUninstall()) { LOGGER.info("Skip cleanup/uninstall is set, enmasse and iot operators won't be deleted"); - } else if (testInfo.isOLMTest()) { - LOGGER.info("Test is OLM"); - if (operatorManager.isEnmasseOlmDeployed()) { - operatorManager.deleteEnmasseOlm(); - } } else if (env.installType() == EnmasseInstallType.BUNDLE) { - if (testInfo.isEndOfIotTests()) { - operatorManager.removeIoT(); - } if (operatorManager.isEnmasseOlmDeployed()) { operatorManager.deleteEnmasseOlm(); } @@ -122,7 +74,7 @@ public void afterAll(ExtensionContext extensionContext) throws Exception { } @Override - public void beforeEach(ExtensionContext context) throws Exception { + public void beforeEach(ExtensionContext context) { testInfo.setCurrentTest(context); ResourceManager.getInstance().setMethodResources(); KubeClusterManager.getInstance().setMethodConfigurations(); @@ -135,44 +87,9 @@ public void afterEach(ExtensionContext extensionContext) throws Exception { LOGGER.info("Teardown section: "); ResourceManager.getInstance().deleteMethodResources(); KubeClusterManager.getInstance().restoreMethodConfigurations(); - if (testInfo.isTestShared()) { - tearDownSharedResources(); - } else if (testInfo.isTestIoT()) { - if (testInfo.needsIoTCleanup()) { - isolatedIoTManager.tearDown(testInfo.getActualTest()); - } - } else { - tearDownCommonResources(); - } }); } - private void tearDownCommonResources() throws Exception { - LOGGER.info("Admin resource manager teardown"); - isolatedResourcesManager.tearDown(testInfo.getActualTest()); - isolatedResourcesManager.unsetReuseAddressSpace(); - isolatedResourcesManager.deleteAddressspacesFromList(); - } - - private void tearDownSharedResources() throws Exception { - if (testInfo.isAddressSpaceDeleteable() || testInfo.getActualTest().getExecutionException().isPresent()) { - if (testInfo.isTestIoT()) { - if (testInfo.needsIoTCleanup()) { - LOGGER.info("Teardown shared IoT!"); - sharedIoTManager.tearDown(testInfo.getActualTest()); - } else { - LOGGER.info("Self-cleaning IoT test"); - sharedIoTManager.closeAmqpFactory(); - } - } else { - LOGGER.info("Teardown shared!"); - sharedResourcesManager.tearDown(testInfo.getActualTest()); - } - } else if (sharedResourcesManager.getSharedAddressSpace() != null) { - sharedResourcesManager.tearDownShared(); - } - } - @Override public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable { saveKubernetesState("Test execution", context, throwable); diff --git a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java index 03c1a0b53c4..11984cd14e1 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/listener/JunitExecutionListener.java @@ -4,22 +4,19 @@ */ package io.enmasse.systemtest.listener; -import org.junit.platform.launcher.TestExecutionListener; -import org.junit.platform.launcher.TestPlan; -import org.slf4j.Logger; - import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.TestTag; import io.enmasse.systemtest.info.TestInfo; import io.enmasse.systemtest.logs.CustomLogger; import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; import io.enmasse.systemtest.operator.EnmasseOperatorManager; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.utils.AddressSpaceUtils; import io.enmasse.systemtest.utils.IoTUtils; +import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestPlan; +import org.slf4j.Logger; /** * Execution listener useful for safety cleanups of the test environment after test suite execution @@ -117,8 +114,6 @@ private void performCleanup() { kube.getAddressSpaceClient().inAnyNamespace().list().getItems().forEach((addrSpace) -> { LOGGER.info("address space '{}' will be removed", addrSpace); try { - AddressSpaceUtils.deleteAddressSpaceAndWait(addrSpace, logCollector); - IsolatedResourcesManager.getInstance().tearDown(TestInfo.getInstance().getActualTest()); } catch (Exception e) { LOGGER.warn("Cleanup failed or no clean is needed"); } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java deleted file mode 100644 index 23ea7ed430b..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedIoTManager.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; - -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.systemtest.utils.ThrowingCallable; - -public class IsolatedIoTManager extends ResourceManager { - - private Logger LOGGER = CustomLogger.getLogger(); - protected AmqpClientFactory amqpClientFactory; - protected List ioTProjects; - protected List ioTConfigs; - private static IsolatedIoTManager instance = null; - private UserCredentials defaultCredentials = environment.getDefaultCredentials(); - - private IsolatedIoTManager() { - ioTProjects = new ArrayList<>(); - ioTConfigs = new ArrayList<>(); - } - - public static synchronized IsolatedIoTManager getInstance() { - if (instance == null) { - instance = new IsolatedIoTManager(); - } - return instance; - } - - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, defaultCredentials); - } - - public void initFactories(IoTProject project) { - String addSpaceName = project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(); - this.initFactories(kubernetes.getAddressSpaceClient(project.getMetadata() - .getNamespace()).withName(addSpaceName).get()); - } - - @Override - public void setup() { - kubernetes.createNamespace(IOT_PROJECT_NAMESPACE); - } - - private static Throwable cleanup(ThrowingCallable callable, Throwable e) { - try { - callable.call(); - return e; - } catch (Throwable e1) { - if (e == null) { - return e1; - } else { - e.addSuppressed(e1); - return e; - } - } - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - - if (environment.skipCleanup()) { - - LOGGER.info("Skip cleanup is set, no cleanup process"); - - } else { - - // the next lines, using cleanup(...) prevent that the failure of - // one cleanup step prevents the next step from being executed. - // Also we must handle Throwables here, since some parts of the code - // call 'assert*', which throws a 'AssertionFailedError', which is - // is an 'Error' rather than an 'Exception'. - - Throwable e = null; - e = cleanup(() -> tearDownProjects(), e); - e = cleanup(() -> tearDownConfigs(), e); - if (context.getExecutionException().isPresent()) { - final Path path = TestUtils.getFailedTestLogsPath(context); - e = cleanup(() -> SystemtestsKubernetesApps.collectInfinispanServerLogs(path), e); - } - e = cleanup(() -> SystemtestsKubernetesApps.deleteInfinispanServer(), e); - e = cleanup(() -> SystemtestsKubernetesApps.deletePostgresqlServer(), e); - e = cleanup(() -> SystemtestsKubernetesApps.deleteH2Server(), e); - - if (e != null) { - LOGGER.error("Error tearing down IoT test: {}", e); - if (e instanceof Exception) { - throw (Exception) e; - } else { - throw new Exception(e); - } - } - - } - } - - private void tearDownProjects() throws Exception { - LOGGER.info("All IoTProjects will be removed"); - for (IoTProject project : ioTProjects) { - var iotProjectApiClient = kubernetes.getIoTProjectClient(project.getMetadata().getNamespace()); - if (iotProjectApiClient.withName(project.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTProjectAndWait(kubernetes, project); - } else { - LOGGER.info("IoTProject '{}' doesn't exists!", project.getMetadata().getName()); - } - } - ioTProjects.clear(); - } - - private void tearDownConfigs() throws Exception { - // delete configs - LOGGER.info("All IoTConfigs will be removed"); - var iotConfigApiClient = kubernetes.getIoTConfigClient(); - for (IoTConfig config : ioTConfigs) { - if (iotConfigApiClient.withName(config.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTConfigAndWait(kubernetes, config); - } else { - LOGGER.info("IoTConfig '{}' doesn't exists!", config.getMetadata().getName()); - } - } - ioTConfigs.clear(); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - - public void createIoTProject(IoTProject project) throws Exception { - ioTProjects.add(project); - IoTUtils.createIoTProject(project); - initFactories(project); - } - - public void deleteIoTProject(IoTProject project) throws Exception { - IoTUtils.deleteIoTProjectAndWait(kubernetes, project); - ioTProjects.remove(project); - } - - public void createIoTConfig(IoTConfig ioTConfig) throws Exception { - ioTConfigs.add(ioTConfig); - IoTUtils.createIoTConfig(ioTConfig); - } - - public void deleteIoTConfig(IoTConfig ioTConfig) throws Exception { - IoTUtils.deleteIoTConfigAndWait(kubernetes, ioTConfig); - ioTConfigs.add(ioTConfig); - } - - public List getIoTProjects() { - return ioTProjects; - } - - public String getTenantId() { - return IoTUtils.getTenantId(ioTProjects.get(0)); - } - - public List getIoTConfigs() { - return ioTConfigs; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java deleted file mode 100644 index f193013f345..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/IsolatedResourcesManager.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.admin.model.v1.BrokeredInfraConfig; -import io.enmasse.admin.model.v1.InfraConfig; -import io.enmasse.admin.model.v1.StandardInfraConfig; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.SystemtestsOperation; -import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.TestUtils; - -public class IsolatedResourcesManager extends ResourceManager { - - private static IsolatedResourcesManager managerInstance = null; - private static Logger LOGGER; - protected AmqpClientFactory amqpClientFactory; - boolean reuseAddressSpace = false; - private ArrayList addressPlans; - private ArrayList addressSpacePlans; - private ArrayList standardInfraConfigs; - private ArrayList brokeredInfraConfigs; - private ArrayList authServices; - private UserCredentials defaultCredentials = environment.getDefaultCredentials(); - - private IsolatedResourcesManager() { - LOGGER = CustomLogger.getLogger(); - addressPlans = new ArrayList<>(); - addressSpacePlans = new ArrayList<>(); - standardInfraConfigs = new ArrayList<>(); - brokeredInfraConfigs = new ArrayList<>(); - authServices = new ArrayList<>(); - currentAddressSpaces = new ArrayList<>(); - } - - //------------------------------------------------------------------------------------------------ - // Singleton handling - //------------------------------------------------------------------------------------------------ - - public List getCurrentAddressSpaces() { - return currentAddressSpaces; - } - - public static synchronized IsolatedResourcesManager getInstance() { - if (managerInstance == null) { - managerInstance = new IsolatedResourcesManager(); - } - return managerInstance; - } - - - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, defaultCredentials); - } - - public void initFactories(AddressSpace addressSpace, UserCredentials userCredentials) throws Exception { - closeClientFactories(amqpClientFactory); - amqpClientFactory = new AmqpClientFactory(addressSpace, userCredentials); - } - - @Override - public void setup() { - if (currentAddressSpaces.isEmpty()) { - initFactories(null); - } else { - initFactories(currentAddressSpaces.get(0)); - } - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - LOGGER.info("Reuse addressspace: " + reuseAddressSpace); - LOGGER.info("Environment cleanup: " + environment.skipCleanup()); - - if (!environment.skipCleanup() && !reuseAddressSpace) { - for (AddressSpacePlan addressSpacePlan : addressSpacePlans) { - Kubernetes.getInstance().getAddressSpacePlanClient().withName(addressSpacePlan.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete addressspace plan", waitPhase -> Kubernetes.getInstance().getAddressSpacePlanClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(addressSpacePlan.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("AddressSpace plan {} deleted", addressSpacePlan.getMetadata().getName()); - } - addressSpacePlans.clear(); - - for (AddressPlan addressPlan : addressPlans) { - Kubernetes.getInstance().getAddressPlanClient().withName(addressPlan.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete address plan", waitPhase -> Kubernetes.getInstance().getAddressPlanClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(addressPlan.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Address plan {} deleted", addressPlan.getMetadata().getName()); - } - addressPlans.clear(); - - for (StandardInfraConfig infraConfigDefinition : standardInfraConfigs) { - Kubernetes.getInstance().getStandardInfraConfigClient().withName(infraConfigDefinition.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete infraConfig plan", waitPhase -> Kubernetes.getInstance().getStandardInfraConfigClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Standardinfraconfig {} deleted", infraConfigDefinition.getMetadata().getName()); - } - standardInfraConfigs.clear(); - - for (BrokeredInfraConfig infraConfigDefinition : brokeredInfraConfigs) { - Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(infraConfigDefinition.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Delete infraConfig plan", waitPhase -> Kubernetes.getInstance().getBrokeredInfraConfigClient().list().getItems().stream().noneMatch(plan -> plan.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - LOGGER.info("Brokeredinfraconfig {} deleted", infraConfigDefinition.getMetadata().getName()); - } - brokeredInfraConfigs.clear(); - - for (AuthenticationService authService : authServices) { - Kubernetes.getInstance().getAuthenticationServiceClient().withName(authService.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitForNReplicas(0, false, authService.getMetadata().getNamespace(), Map.of("name", authService.getMetadata().getName()), Collections.emptyMap(), new TimeoutBudget(1, TimeUnit.MINUTES), 5000); - LOGGER.info("AuthService {} deleted", authService.getMetadata().getName()); - } - authServices.clear(); - - - closeClientFactories(amqpClientFactory); - amqpClientFactory = null; - } else { - LOGGER.warn("No custom resources are deleted, SKIP_CLEANUP is set"); - } - - } - - - //------------------------------------------------------------------------------------------------ - // Address plans - //------------------------------------------------------------------------------------------------ - - @Override - public void createAddressPlan(AddressPlan addressPlan) throws Exception { - addressPlans.add(addressPlan); - super.createAddressPlan(addressPlan); - } - - @Override - public void removeAddressPlan(AddressPlan addressPlan) throws Exception { - super.removeAddressPlan(addressPlan); - addressPlans.removeIf(addressPlanIter -> addressPlanIter.getMetadata().getName().equals(addressPlan.getMetadata().getName())); - } - - @Override - public void replaceAddressPlan(AddressPlan plan) throws InterruptedException { - super.replaceAddressPlan(plan); - } - - @Override - public AddressPlan getAddressPlan(String name) throws Exception { - return super.getAddressPlan(name); - } - - //------------------------------------------------------------------------------------------------ - // Address space plans - //------------------------------------------------------------------------------------------------ - - @Override - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - addressSpacePlans.add(addressSpacePlan); - super.createAddressSpacePlan(addressSpacePlan); - } - - @Override - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan, boolean wait) throws Exception { - addressSpacePlans.add(addressSpacePlan); - super.createAddressSpacePlan(addressSpacePlan, wait); - } - - @Override - public void removeAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - super.removeAddressSpacePlan(addressSpacePlan); - addressSpacePlans.removeIf(spacePlanIter -> spacePlanIter.getMetadata().getName().equals(addressSpacePlan.getMetadata().getName())); - } - - @Override - public AddressSpacePlan getAddressSpacePlan(String config) throws Exception { - return super.getAddressSpacePlan(config); - } - - //------------------------------------------------------------------------------------------------ - // Infra configs - //------------------------------------------------------------------------------------------------ - - @Override - public BrokeredInfraConfig getBrokeredInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(name).get(); - } - - @Override - public StandardInfraConfig getStandardInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getStandardInfraConfigClient().withName(name).get(); - } - - @Override - public void createInfraConfig(StandardInfraConfig standardInfraConfig) { - standardInfraConfigs.add(standardInfraConfig); - super.createInfraConfig(standardInfraConfig); - } - - @Override - public void createInfraConfig(BrokeredInfraConfig brokeredInfraConfig) { - brokeredInfraConfigs.add(brokeredInfraConfig); - super.createInfraConfig(brokeredInfraConfig); - } - - public void createInfraConfig(InfraConfig infraConfigDefinition) throws Exception { - if (infraConfigDefinition instanceof StandardInfraConfig) { - standardInfraConfigs.add((StandardInfraConfig) infraConfigDefinition); - super.createInfraConfig((StandardInfraConfig) infraConfigDefinition); - } else { - brokeredInfraConfigs.add((BrokeredInfraConfig) infraConfigDefinition); - super.createInfraConfig((BrokeredInfraConfig) infraConfigDefinition); - } - } - - public void removeInfraConfig(InfraConfig infraConfigDefinition) throws Exception { - if (infraConfigDefinition instanceof StandardInfraConfig) { - super.removeInfraConfig((StandardInfraConfig) infraConfigDefinition); - standardInfraConfigs.removeIf(infraId -> infraId.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())); - } else { - super.removeInfraConfig((BrokeredInfraConfig) infraConfigDefinition); - brokeredInfraConfigs.removeIf(infraId -> infraId.getMetadata().getName().equals(infraConfigDefinition.getMetadata().getName())); - } - } - - //------------------------------------------------------------------------------------------------ - // Authentication services - //------------------------------------------------------------------------------------------------ - - @Override - public void replaceAuthService(AuthenticationService authService) throws Exception { - replaceAuthService(authService, false); - } - - public void replaceAuthService(AuthenticationService authenticationService, boolean replaceExisting) throws Exception { - if (replaceExisting) { - super.replaceAuthService(authenticationService); - } else { - super.createAuthService(authenticationService); - authServices.add(authenticationService); - } - } - - @Override - public void createAuthService(AuthenticationService authenticationService) throws Exception { - authServices.add(authenticationService); - super.createAuthService(authenticationService); - } - - @Override - public void createAuthService(AuthenticationService authenticationService, boolean wait) throws Exception { - authServices.add(authenticationService); - super.createAuthService(authenticationService, wait); - } - - @Override - public void removeAuthService(AuthenticationService authService) throws Exception { - super.removeAuthService(authService); - authServices.removeIf(authserviceId -> authserviceId.getMetadata().getName().equals(authService.getMetadata().getName())); - } - - @Override - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - createAddressSpace(addressSpace, true); - } - - @Override - public void createAddressSpace(AddressSpace addressSpace, boolean waitForReady) throws Exception { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - currentAddressSpaces.add(addressSpace); - super.createAddressSpace(addressSpace, waitForReady); - } else { - if (waitForReady) { - super.waitForAddressSpaceReady(addressSpace); - } - } - } - - public void setReuseAddressSpace() { - reuseAddressSpace = true; - } - - public void unsetReuseAddressSpace() { - reuseAddressSpace = false; - } - - //================================================================================================ - //==================================== AddressSpace methods ====================================== - //================================================================================================ - - public void createAddressSpaceList(AddressSpace... addressSpaces) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - ArrayList spaces = new ArrayList<>(); - for (AddressSpace addressSpace : addressSpaces) { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '" + addressSpace + "' doesn't exist and will be created."); - spaces.add(addressSpace); - } else { - LOGGER.warn("Address space '" + addressSpace + "' already exists."); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - currentAddressSpaces.add(addressSpace); - } - } - currentAddressSpaces.addAll(spaces); - super.createAddressSpaces(spaces, operationID); - } - - public void replaceAddressSpace(AddressSpace addressSpace) throws Exception { - replaceAddressSpace(addressSpace, true, null); - } - - public void deleteAddressspacesFromList() throws Exception { - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info("All addressspaces will be removed"); - for (AddressSpace addressSpace : currentAddressSpaces) { - deleteAddressSpace(addressSpace); - } - currentAddressSpaces.clear(); - } - } - - @Override - public void addToAddressSpaces(AddressSpace addressSpace) { - this.currentAddressSpaces.add(addressSpace); - } - - @Override - public void deleteAddressSpaceCreatedBySC(AddressSpace addressSpace) throws Exception { - TestUtils.deleteAddressSpaceCreatedBySC(kubernetes, addressSpace, logCollector); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java deleted file mode 100644 index d1bb14d3e33..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/ResourceManager.java +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; - -import java.util.List; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.*; -import io.enmasse.config.AnnotationKeys; -import io.enmasse.systemtest.Environment; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.SystemtestsOperation; -import io.enmasse.systemtest.time.TimeMeasuringSystem; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthenticationType; -import io.enmasse.user.model.v1.UserBuilder; -import io.fabric8.kubernetes.api.model.Pod; - -public abstract class ResourceManager { - protected static final Environment environment = Environment.getInstance(); - protected static final Kubernetes kubernetes = Kubernetes.getInstance(); - protected static final GlobalLogCollector logCollector = new GlobalLogCollector(kubernetes, environment.testLogDir()); - private static Logger LOGGER = CustomLogger.getLogger(); - - protected String defaultAddSpaceIdentifier; - protected String addressSpaceType; - protected String addressSpacePlan; - protected List currentAddressSpaces; - - public void setDefaultAddSpaceIdentifier(String defaultAddSpaceIdentifier) { - this.defaultAddSpaceIdentifier = defaultAddSpaceIdentifier; - } - - public void setAddressSpaceType(String addressSpaceType) { - this.addressSpaceType = addressSpaceType; - } - - public void setAddressSpacePlan(String addressSpacePlan) { - this.addressSpacePlan = addressSpacePlan; - } - - public abstract void setup() throws Exception; - - public abstract void tearDown(ExtensionContext context) throws Exception; - - public abstract AmqpClientFactory getAmqpClientFactory(); - - public abstract void setAmqpClientFactory(AmqpClientFactory amqpClientFactory); - - public AddressSpace getSharedAddressSpace() { - return null; - } - - public void addToAddressSpaces(AddressSpace addressSpace) throws Exception { - throw new Exception("Not implemented in resource manager"); - } - - public void deleteAddressSpaceCreatedBySC(AddressSpace addressSpace) throws Exception { - throw new Exception("Not implemented in resource manager"); - } - - //------------------------------------------------------------------------------------------------ - // Client factories - //------------------------------------------------------------------------------------------------ - - public void closeClientFactories(AmqpClientFactory amqpClientFactory) throws Exception { - if (amqpClientFactory != null) { - amqpClientFactory.close(); - } - } - - //------------------------------------------------------------------------------------------------ - // Address plans - //------------------------------------------------------------------------------------------------ - - public void createAddressPlan(AddressPlan addressPlan) throws Exception { - LOGGER.info("Address plan {} will be created {}", addressPlan.getMetadata().getName(), addressPlan); - var client = Kubernetes.getInstance().getAddressPlanClient(); - client.create(addressPlan); - Thread.sleep(1000); - } - - public void replaceAddressPlan(AddressPlan addressPlan) throws InterruptedException { - LOGGER.info("Address plan {} will be replaced {}", addressPlan.getMetadata().getName(), addressPlan); - var client = Kubernetes.getInstance().getAddressPlanClient(); - client.createOrReplace(addressPlan); - Thread.sleep(1000); - } - - public void removeAddressPlan(AddressPlan addressPlan) throws Exception { - Kubernetes.getInstance().getAddressPlanClient().withName(addressPlan.getMetadata().getName()).cascading(true).delete(); - } - - public AddressPlan getAddressPlan(String name) throws Exception { - return Kubernetes.getInstance().getAddressPlanClient().withName(name).get(); - } - - //------------------------------------------------------------------------------------------------ - // Address space plans - //------------------------------------------------------------------------------------------------ - - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - createAddressSpacePlan(addressSpacePlan, true); - } - - public void createAddressSpacePlan(AddressSpacePlan addressSpacePlan, boolean wait) throws Exception { - LOGGER.info("AddressSpace plan {} will be created {}", addressSpacePlan.getMetadata().getName(), addressSpacePlan); - if (addressSpacePlan.getMetadata().getNamespace() == null || addressSpacePlan.getMetadata().getNamespace().equals("")) { - addressSpacePlan.getMetadata().setNamespace(Kubernetes.getInstance().getInfraNamespace()); - } - var client = Kubernetes.getInstance().getAddressSpacePlanClient(); - client.create(addressSpacePlan); - if (wait) { - TestUtils.waitForSchemaInSync(addressSpacePlan.getMetadata().getName()); - } - Thread.sleep(1000); - } - - public void removeAddressSpacePlan(AddressSpacePlan addressSpacePlan) throws Exception { - Kubernetes.getInstance().getAddressSpacePlanClient().withName(addressSpacePlan.getMetadata().getName()).cascading(true).delete(); - } - - public AddressSpacePlan getAddressSpacePlan(String config) throws Exception { - return Kubernetes.getInstance().getAddressSpacePlanClient().withName(config).get(); - } - - //------------------------------------------------------------------------------------------------ - // Infra configs - //------------------------------------------------------------------------------------------------ - - public BrokeredInfraConfig getBrokeredInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getBrokeredInfraConfigClient().withName(name).get(); - } - - public StandardInfraConfig getStandardInfraConfig(String name) throws Exception { - return Kubernetes.getInstance().getStandardInfraConfigClient().withName(name).get(); - } - - public void createInfraConfig(StandardInfraConfig standardInfraConfig) { - LOGGER.info("StandardInfraConfig {} will be created {}", standardInfraConfig.getMetadata().getName(), standardInfraConfig); - var client = Kubernetes.getInstance().getStandardInfraConfigClient(); - client.createOrReplace(standardInfraConfig); - } - - public void createInfraConfig(BrokeredInfraConfig brokeredInfraConfig) { - LOGGER.info("BrokeredInfraConfig {} will be created {}", brokeredInfraConfig.getMetadata().getName(), brokeredInfraConfig); - var client = Kubernetes.getInstance().getBrokeredInfraConfigClient(); - client.createOrReplace(brokeredInfraConfig); - } - - public void removeInfraConfig(StandardInfraConfig infraConfig) { - var client = Kubernetes.getInstance().getStandardInfraConfigClient(); - client.withName(infraConfig.getMetadata().getName()).cascading(true).delete(); - } - - public void removeInfraConfig(BrokeredInfraConfig infraConfig) { - var client = Kubernetes.getInstance().getBrokeredInfraConfigClient(); - client.withName(infraConfig.getMetadata().getName()).cascading(true).delete(); - } - - //------------------------------------------------------------------------------------------------ - // Authentication services - //------------------------------------------------------------------------------------------------ - - public AuthenticationService getAuthService(String name) { - return Kubernetes.getInstance().getAuthenticationServiceClient().withName(name).get(); - } - - public void createAuthService(AuthenticationService authenticationService) throws Exception { - createAuthService(authenticationService, true); - } - - public void createAuthService(AuthenticationService authenticationService, boolean wait) throws Exception { - var client = Kubernetes.getInstance().getAuthenticationServiceClient(); - LOGGER.info("AuthService {} will be created {}", authenticationService.getMetadata().getName(), authenticationService); - client.create(authenticationService); - if (wait) { - waitForAuthPods(authenticationService); - } - } - - - public void replaceAuthService(AuthenticationService authenticationService) throws Exception { - LOGGER.info("AuthService {} will be created {}", authenticationService.getMetadata().getName(), authenticationService); - var client = Kubernetes.getInstance().getAuthenticationServiceClient(); - client.createOrReplace(authenticationService); - waitForAuthPods(authenticationService); - } - - public void waitForAuthPods(AuthenticationService authenticationService) throws Exception { - String desiredPodName = authenticationService.getMetadata().getName(); - int expectedMatches = 1; - if (authenticationService.getSpec().getType().equals(AuthenticationServiceType.none) && - authenticationService.getSpec().getNone() != null && - authenticationService.getSpec().getNone().getReplicas() != null) { - expectedMatches = authenticationService.getSpec().getNone().getReplicas(); - } else if (authenticationService.getSpec().getType().equals(AuthenticationServiceType.standard) && - authenticationService.getSpec().getStandard() != null && - authenticationService.getSpec().getStandard().getReplicas() != null) { - expectedMatches = authenticationService.getSpec().getStandard().getReplicas(); - } - int finalExpectedMatches = expectedMatches; - TestUtils.waitUntilCondition("Auth service is deployed: " + desiredPodName, phase -> { - List pods = TestUtils.listReadyPods(Kubernetes.getInstance(), authenticationService.getMetadata().getNamespace()); - long matching = pods.stream().filter(pod -> - pod.getMetadata().getName().contains(desiredPodName)).count(); - if (matching != finalExpectedMatches) { - List podNames = pods.stream().map(p -> p.getMetadata().getName()).collect(Collectors.toList()); - LOGGER.info("Still awaiting pod with name : {}, matching : {}, current pods {}", - desiredPodName, matching, podNames); - } - - return matching == finalExpectedMatches; - }, - new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - public void removeAuthService(AuthenticationService authService) throws Exception { - Kubernetes.getInstance().getAuthenticationServiceClient(authService.getMetadata().getNamespace()) - .withName(authService.getMetadata().getName()).cascading(true).delete(); - TestUtils.waitUntilCondition("Auth service is deleted: " + authService.getMetadata().getName(), (phase) -> - TestUtils.listReadyPods(Kubernetes.getInstance(), authService.getMetadata().getNamespace()).stream().noneMatch(pod -> - pod.getMetadata().getName().contains(authService.getMetadata().getName())), - new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - createAddressSpace(addressSpace, true); - } - - public void createAddressSpace(AddressSpace addressSpace, boolean waitUntilReady) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' doesn't exist and will be created.", addressSpace); - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace); - if (waitUntilReady) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } - } else { - if (waitUntilReady) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } - LOGGER.info("Address space '" + addressSpace + "' already exists."); - } - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - public void createAddressSpace(AddressSpace... addressSpaces) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - for (AddressSpace addressSpace : addressSpaces) { - if (!AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' doesn't exist and will be created.", addressSpace); - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace); - } else { - LOGGER.info("Address space '" + addressSpace + "' already exists."); - } - } - for (AddressSpace addressSpace : addressSpaces) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - } - TimeMeasuringSystem.stopOperation(operationID); - } - - public void waitForAddressSpaceReady(AddressSpace addressSpace) throws Exception { - LOGGER.info("Waiting for address space ready"); - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.CREATE_ADDRESS_SPACE); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - //------------------------------------------------------------------------------------------------ - // Address space methods - //------------------------------------------------------------------------------------------------ - - public void deleteAddressSpace(AddressSpace addressSpace) throws Exception { - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - AddressSpaceUtils.deleteAddressSpaceAndWait(addressSpace, logCollector); - } else { - LOGGER.info("Address space '" + addressSpace.getMetadata().getName() + "' doesn't exists!"); - } - } - - public void deleteAddressSpaceWithoutWait(AddressSpace addressSpace) throws Exception { - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - AddressSpaceUtils.deleteAddressSpace(addressSpace, logCollector); - } else { - LOGGER.info("Address space '" + addressSpace.getMetadata().getName() + "' doesn't exists!"); - } - } - - protected void createAddressSpaces(List addressSpaces, String operationID) throws Exception { - addressSpaces.forEach(addressSpace -> - kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()).createOrReplace(addressSpace)); - for (AddressSpace addressSpace : addressSpaces) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - } - TimeMeasuringSystem.stopOperation(operationID); - } - - public void replaceAddressSpace(AddressSpace addressSpace, boolean waitForConfigApplied, TimeoutBudget waitBudget) throws Exception { - String operationID = TimeMeasuringSystem.startOperation(SystemtestsOperation.UPDATE_ADDRESS_SPACE); - var client = kubernetes.getAddressSpaceClient(addressSpace.getMetadata().getNamespace()); - if (AddressSpaceUtils.existAddressSpace(addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName())) { - LOGGER.info("Address space '{}' exists and will be updated.", addressSpace); - final AddressSpace current = client.withName(addressSpace.getMetadata().getName()).get(); - final String currentResourceVersion = current.getMetadata().getResourceVersion(); - final String currentConfig = current.getAnnotation(AnnotationKeys.APPLIED_CONFIGURATION); - client.createOrReplace(addressSpace); - Thread.sleep(10_000); - TestUtils.waitForChangedResourceVersion(ofDuration(ofMinutes(5)), addressSpace.getMetadata().getNamespace(), addressSpace.getMetadata().getName(), currentResourceVersion); - if (waitForConfigApplied) { - AddressSpaceUtils.waitForAddressSpaceConfigurationApplied(addressSpace, currentConfig); - } - if (waitBudget == null) { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - } else { - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace, waitBudget); - } - - AddressSpaceUtils.syncAddressSpaceObject(addressSpace); - currentAddressSpaces.add(addressSpace); - } else { - LOGGER.info("Address space '{}' does not exists.", addressSpace.getMetadata().getName()); - } - LOGGER.info("Address space updated: {}", addressSpace); - TimeMeasuringSystem.stopOperation(operationID); - } - - public AddressSpace getAddressSpace(String namespace, String addressSpaceName) { - return kubernetes.getAddressSpaceClient(namespace).withName(addressSpaceName).get(); - } - - public AddressSpace getAddressSpace(String addressSpaceName) { - return kubernetes.getAddressSpaceClient().withName(addressSpaceName).get(); - } - - - //================================================================================================ - //====================================== Address methods ========================================= - //================================================================================================ - - public void deleteAddresses(Address... destinations) { - logCollector.collectRouterState("deleteAddresses"); - AddressUtils.delete(destinations); - } - - public void deleteAddresses(AddressSpace addressSpace) throws Exception { - LOGGER.info("Addresses in " + addressSpace.getMetadata().getName() + " will be deleted!"); - logCollector.collectRouterState("deleteAddresses"); - AddressUtils.delete(addressSpace); - } - - - public void appendAddresses(Address... destinations) throws Exception { - TimeoutBudget budget = new TimeoutBudget(15, TimeUnit.MINUTES); - appendAddresses(budget, destinations); - } - - public void appendAddresses(TimeoutBudget timeout, Address... destinations) throws Exception { - appendAddresses(true, timeout, destinations); - } - - public void appendAddresses(boolean wait, Address... destinations) throws Exception { - TimeoutBudget budget = new TimeoutBudget(15, TimeUnit.MINUTES); - appendAddresses(wait, budget, destinations); - } - - private void appendAddresses(boolean wait, TimeoutBudget timeout, Address... destinations) throws Exception { - AddressUtils.appendAddresses(timeout, wait, destinations); - } - - public void setAddresses(TimeoutBudget budget, Address... addresses) throws Exception { - logCollector.collectRouterState("setAddresses"); - AddressUtils.setAddresses(budget, true, addresses); - } - - public void setAddresses(boolean wait, Address... addresses) throws Exception { - logCollector.collectRouterState("setAddresses"); - AddressUtils.setAddresses(null, wait, addresses); - } - - public void setAddresses(Address... addresses) throws Exception { - setAddresses(new TimeoutBudget(15, TimeUnit.MINUTES), addresses); - } - - public void replaceAddress(Address destination) throws Exception { - AddressUtils.replaceAddress(destination, true, new TimeoutBudget(10, TimeUnit.MINUTES)); - } - - public Address getAddress(String namespace, Address destination) { - return kubernetes.getAddressClient().inNamespace(namespace).withName(destination.getMetadata().getName()).get(); - } - - //================================================================================================ - //======================================= User methods =========================================== - //================================================================================================ - - public User createOrUpdateUser(AddressSpace addressSpace, UserCredentials credentials) throws Exception { - return createOrUpdateUser(addressSpace, credentials, true); - } - - public User createOrUpdateUser(AddressSpace addressSpace, UserCredentials credentials, boolean wait) throws Exception { - Objects.requireNonNull(addressSpace); - Objects.requireNonNull(credentials); - User user = new UserBuilder() - .withNewMetadata() - .withName(addressSpace.getMetadata().getName() + "." + credentials.getUsername()) - .endMetadata() - .withNewSpec() - .withUsername(credentials.getUsername()) - .withNewAuthentication() - .withType(UserAuthenticationType.password) - .withNewPassword(UserUtils.passwordToBase64(credentials.getPassword())) - .endAuthentication() - .addNewAuthorization() - .withAddresses("*") - .addToOperations(Operation.send) - .addToOperations(Operation.recv) - .endAuthorization() - .addNewAuthorization() - .addToOperations(Operation.manage) - .endAuthorization() - .endSpec() - .build(); - return createOrUpdateUser(addressSpace, user, wait); - } - - public User createOrUpdateUser(AddressSpace addressSpace, User user) throws Exception { - return createOrUpdateUser(addressSpace, user, true); - } - - public User createOrUpdateUser(AddressSpace addressSpace, User user, boolean wait) throws Exception { - if (user.getMetadata().getName() == null || !user.getMetadata().getName().contains(addressSpace.getMetadata().getName())) { - user.getMetadata().setName(addressSpace.getMetadata().getName() + "." + user.getSpec().getUsername()); - } - if (user.getMetadata().getNamespace() == null) { - user.getMetadata().setNamespace(addressSpace.getMetadata().getNamespace()); - } - LOGGER.info("User {} in address space {} will be created/replaced", user, addressSpace.getMetadata().getName()); - User existing = kubernetes.getUserClient(user.getMetadata().getNamespace()).withName(user.getMetadata().getName()).get(); - if (existing != null) { - existing.setSpec(user.getSpec()); - user = existing; - } - kubernetes.getUserClient(user.getMetadata().getNamespace()).createOrReplace(user); - if (wait) { - return UserUtils.waitForUserActive(user, new TimeoutBudget(1, TimeUnit.MINUTES)); - } - return kubernetes.getUserClient(user.getMetadata().getNamespace()).withName(user.getMetadata().getName()).get(); - } - - public User createUserServiceAccount(AddressSpace addressSpace, UserCredentials cred) throws Exception { - LOGGER.info("ServiceAccount user {} in address space {} will be created", cred.getUsername(), addressSpace.getMetadata().getName()); - String serviceaccountName = kubernetes.createServiceAccount(cred.getUsername(), addressSpace.getMetadata().getNamespace()); - User user = new UserBuilder() - .withNewMetadata() - .withName(String.format("%s.%s", addressSpace.getMetadata().getName(), - Pattern.compile(".*:").matcher(serviceaccountName).replaceAll(""))) - .endMetadata() - .withNewSpec() - .withUsername(serviceaccountName) - .withNewAuthentication() - .withType(UserAuthenticationType.serviceaccount) - .endAuthentication() - .addNewAuthorization() - .withAddresses("*") - .addToOperations(Operation.send) - .addToOperations(Operation.recv) - .endAuthorization() - .endSpec() - .build(); - return createOrUpdateUser(addressSpace, user); - } - - public void removeUser(AddressSpace addressSpace, User user) throws InterruptedException { - Objects.requireNonNull(addressSpace); - Objects.requireNonNull(user); - LOGGER.info("User {} in address space {} will be removed", user.getMetadata().getName(), addressSpace.getMetadata().getName()); - kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).withName(user.getMetadata().getName()).cascading(true).delete(); - UserUtils.waitForUserDeleted(user.getMetadata().getNamespace(), user.getMetadata().getName(), new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public void removeUser(AddressSpace addressSpace, String userName) throws InterruptedException { - Objects.requireNonNull(addressSpace); - LOGGER.info("User {} in address space {} will be removed", userName, addressSpace.getMetadata().getName()); - String name = String.format("%s.%s", addressSpace.getMetadata().getName(), userName); - kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).withName(name).cascading(true).delete(); - UserUtils.waitForUserDeleted(addressSpace.getMetadata().getNamespace(), name, new TimeoutBudget(1, TimeUnit.MINUTES)); - } - - public User getUser(AddressSpace addressSpace, String username) { - String id = String.format("%s.%s", addressSpace.getMetadata().getName(), username); - List response = kubernetes.getUserClient(addressSpace.getMetadata().getNamespace()).list().getItems(); - LOGGER.info("User list for {}: {}", addressSpace.getMetadata().getName(), response); - for (User user : response) { - if (user.getMetadata().getName().equals(id)) { - LOGGER.info("User {} in addressspace {} already exists", username, addressSpace.getMetadata().getName()); - return user; - } - } - return null; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java deleted file mode 100644 index 8e282c6319f..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedIoTManager.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.manager; - -import static io.enmasse.systemtest.bases.iot.ITestIoTBase.IOT_PROJECT_NAMESPACE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.utils.IoTUtils.createIoTConfig; -import static io.enmasse.systemtest.utils.IoTUtils.createIoTProject; - -import java.nio.file.Path; -import java.util.UUID; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; - - -public class SharedIoTManager extends ResourceManager { - - private static final Logger LOGGER = CustomLogger.getLogger(); - private static SharedIoTManager instance; - protected AmqpClientFactory amqpClientFactory = null; - private IoTProject sharedIoTProject = null; - private IoTConfig sharedIoTConfig = null; - private AmqpClient amqpClient; - - private SharedIoTManager() { - } - - public static synchronized SharedIoTManager getInstance() { - if (instance == null) { - instance = new SharedIoTManager(); - } - return instance; - } - - @Override - public AddressSpace getSharedAddressSpace() { - if (sharedIoTProject == null) { - return null; - } - String addSpaceName = sharedIoTProject.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(); - return kubernetes.getAddressSpaceClient(sharedIoTProject.getMetadata().getNamespace()).withName(addSpaceName).get(); - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - closeAmqpFactory(); - if (environment.skipCleanup()) { - LOGGER.info("Skip cleanup is set, no cleanup process"); - } else { - if (sharedIoTProject != null) { - LOGGER.info("Shared IoTProject will be removed"); - var iotProjectApiClient = kubernetes.getIoTProjectClient(sharedIoTProject.getMetadata().getNamespace()); - if (iotProjectApiClient.withName(sharedIoTProject.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTProjectAndWait(kubernetes, sharedIoTProject); - sharedIoTProject = null; - } else { - LOGGER.info("IoTProject '{}' doesn't exists!", sharedIoTProject.getMetadata().getName()); - } - } - tearDownSharedIoTConfig(); - if (context.getExecutionException().isPresent()) { - Path path = TestUtils.getFailedTestLogsPath(context); - SystemtestsKubernetesApps.collectInfinispanServerLogs(path); - } - SystemtestsKubernetesApps.deleteInfinispanServer(); - SystemtestsKubernetesApps.deletePostgresqlServer(); - SystemtestsKubernetesApps.deleteH2Server(); - } - } - - public void tearDownSharedIoTConfig() throws Exception { - if (sharedIoTConfig != null) { - LOGGER.info("Shared IoTConfig will be removed"); - var iotConfigApiClient = kubernetes.getIoTConfigClient(); - if (iotConfigApiClient.withName(sharedIoTConfig.getMetadata().getName()).get() != null) { - IoTUtils.deleteIoTConfigAndWait(kubernetes, sharedIoTConfig); - sharedIoTConfig = null; - } else { - LOGGER.info("IoTConfig '{}' doesn't exists!", sharedIoTConfig.getMetadata().getName()); - } - } - } - - void initFactories(UserCredentials credentials) { - amqpClientFactory = new AmqpClientFactory(getSharedAddressSpace(), credentials); - } - - @Override - public void setup() throws Exception { - kubernetes.createNamespace(IOT_PROJECT_NAMESPACE); - - UserCredentials credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - - if (sharedIoTConfig == null) { - createNewIoTConfig(); - } - - if (sharedIoTProject == null) { - sharedIoTProject = IoTUtils.getBasicIoTProjectObject("shared-iot-project", defaultAddSpaceIdentifier, IOT_PROJECT_NAMESPACE, addressSpacePlan); - createIoTProject(sharedIoTProject); - } - initFactories(credentials); - createOrUpdateUser(getSharedAddressSpace(), credentials); - this.amqpClient = amqpClientFactory.createQueueClient(); - } - - private void createNewIoTConfig() throws Exception { - sharedIoTConfig = IoTTestSession - .createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - - createIoTConfig(sharedIoTConfig); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - - public IoTProject getSharedIoTProject() { - return sharedIoTProject; - } - - public IoTConfig getSharedIoTConfig() { - return sharedIoTConfig; - } - - public String getTenantId() { - return IoTUtils.getTenantId(sharedIoTProject); - } - - public AmqpClient getAmqpClient() { - return amqpClient; - } - - public void closeAmqpFactory() throws Exception { - if (amqpClientFactory != null) { - amqpClientFactory.close(); - amqpClientFactory = null; - } - } -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java deleted file mode 100644 index 8140c7157c1..00000000000 --- a/systemtests/src/main/java/io/enmasse/systemtest/manager/SharedResourceManager.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.manager; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; - -public class SharedResourceManager extends ResourceManager { - private static final Logger LOGGER = CustomLogger.getLogger(); - private static SharedResourceManager instance; - private static Map spaceCountMap = new HashMap<>(); - protected AmqpClientFactory amqpClientFactory = null; - private AddressSpace sharedAddressSpace = null; - private static final String DEFAULT_ADDRESS_TEMPLATE = "-shared-"; - private UserCredentials defaultCredentials = environment.getSharedDefaultCredentials(); - private UserCredentials managementCredentials = environment.getSharedManagementCredentials(); - - public static synchronized SharedResourceManager getInstance() { - if (instance == null) { - instance = new SharedResourceManager(); - } - return instance; - } - - @Override - public AddressSpace getSharedAddressSpace() { - return sharedAddressSpace; - } - - @Override - public void tearDown(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info(String.format("test failed: %s.%s", - context.getRequiredTestClass().getName(), - context.getRequiredTestMethod().getName())); - LOGGER.info("shared address space '{}' will be removed", sharedAddressSpace); - try { - if (sharedAddressSpace != null) { - super.deleteAddressSpace(sharedAddressSpace); - } - } catch (Exception ex) { - LOGGER.warn("Failed to delete shared address space (ignored)", ex); - } finally { - spaceCountMap.compute(defaultAddSpaceIdentifier, (k, count) -> count == null ? null : count + 1); - } - } - } else { //succeed - try { - if (environment.skipCleanup()) { - LOGGER.warn("No address space is deleted, SKIP_CLEANUP is set"); - } else { - LOGGER.info("Shared address space will be deleted!"); - super.deleteAddressSpace(sharedAddressSpace); - } - } catch (Exception e) { - LOGGER.warn("Failed to delete addresses from shared address space (ignored)", e); - } - } - closeClientFactories(amqpClientFactory); - amqpClientFactory = null; - sharedAddressSpace = null; - } - - void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(sharedAddressSpace, defaultCredentials); - } - - @Override - public void setup() throws Exception { - LOGGER.info("Shared setup"); - if (spaceCountMap == null) { - spaceCountMap = new HashMap<>(); - } - spaceCountMap.putIfAbsent(defaultAddSpaceIdentifier, 0); - sharedAddressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName(defaultAddSpaceIdentifier + DEFAULT_ADDRESS_TEMPLATE + spaceCountMap.get(defaultAddSpaceIdentifier)) - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(addressSpaceType) - .withPlan(addressSpacePlan) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - createSharedAddressSpace(sharedAddressSpace); - createOrUpdateUser(sharedAddressSpace, managementCredentials); - createOrUpdateUser(sharedAddressSpace, defaultCredentials); - initFactories(sharedAddressSpace); - } - - public void createSharedAddressSpace(AddressSpace addressSpace) throws Exception { - super.createAddressSpace(addressSpace); - sharedAddressSpace = addressSpace; - } - - @Override - public void createAddressSpace(AddressSpace addressSpace) throws Exception { - super.createAddressSpace(addressSpace); - } - - public void tearDownShared() throws Exception { - LOGGER.info("Deleting addresses"); - deleteAddresses(sharedAddressSpace); - LOGGER.info("Closing clients"); - closeClientFactories(amqpClientFactory); - initFactories(sharedAddressSpace); - } - - @Override - public AmqpClientFactory getAmqpClientFactory() { - return amqpClientFactory; - } - - @Override - public void setAmqpClientFactory(AmqpClientFactory amqpClientFactory) { - this.amqpClientFactory = amqpClientFactory; - } - -} diff --git a/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java b/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java index c9e47b8100e..14b6a2f8239 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/messaginginfra/ResourceManager.java @@ -142,9 +142,6 @@ public void setDefaultMessagingTenant(MessagingTenant tenant) { // Client factories //------------------------------------------------------------------------------------------------ - public void initFactories(AddressSpace addressSpace) { - amqpClientFactory = new AmqpClientFactory(addressSpace, environment.getSharedDefaultCredentials()); - } public void initFactories(AddressSpace addressSpace, UserCredentials cred) { amqpClientFactory = new AmqpClientFactory(addressSpace, cred); diff --git a/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java b/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java index 08ba9d557f5..0d401210177 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/operator/EnmasseOperatorManager.java @@ -4,22 +4,6 @@ */ package io.enmasse.systemtest.operator; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import org.slf4j.Logger; - import io.enmasse.admin.model.v1.ConsoleService; import io.enmasse.admin.model.v1.ConsoleServiceSpec; import io.enmasse.systemtest.Environment; @@ -33,8 +17,23 @@ import io.enmasse.systemtest.platform.OpenShift; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.EnvVar; import io.fabric8.kubernetes.api.model.ConfigMapBuilder; +import io.fabric8.kubernetes.api.model.EnvVar; +import org.slf4j.Logger; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EnmasseOperatorManager { @@ -62,22 +61,12 @@ public OLMOperatorManager olm() { } public void installEnmasseBundle() throws Exception { - LOGGER.info("***********************************************************"); - LOGGER.info(" Enmasse operator install"); - LOGGER.info("***********************************************************"); - installOperators(); - installExamplesBundle(kube.getInfraNamespace()); - waitUntilOperatorReady(kube.getInfraNamespace()); - LOGGER.info("***********************************************************"); - } - - public void installEnmasseSharedInfraBundle() throws Exception { LOGGER.info("***********************************************************"); LOGGER.info(" Enmasse operator shared infra install"); LOGGER.info("***********************************************************"); generateTemplates(); kube.createNamespace(kube.getInfraNamespace(), Collections.singletonMap("allowed", "true")); - KubeCMDClient.applyFromFile(kube.getInfraNamespace(), Paths.get(Environment.getInstance().getTemplatesPath(), "install", "preview-bundles", "enmasse")); + KubeCMDClient.applyFromFile(kube.getInfraNamespace(), Paths.get(Environment.getInstance().getTemplatesPath(), "install", "preview-bundles", "enmasse")); //TODO change it once it will be moved TestUtils.waitUntilDeployed(kube.getInfraNamespace()); LOGGER.info("***********************************************************"); } @@ -437,8 +426,7 @@ private void awaitConsoleReadiness(String namespace) throws Exception { public boolean isEnmasseBundleDeployed() { return kube.namespaceExists(kube.getInfraNamespace()) - && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("enmasse-operator")).count() == 1 - && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("address-space-controller")).count() == 1; + && kube.listPods(kube.getInfraNamespace()).stream().filter(pod -> pod.getMetadata().getName().contains("enmasse-operator")).count() == 1; } public boolean isEnmasseOlmDeployed() { diff --git a/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java b/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java index 2430b17f0a1..5acab5f0c2e 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/platform/KubeCMDClient.java @@ -18,7 +18,6 @@ import java.util.Objects; import java.util.Optional; -import io.enmasse.systemtest.bases.ITestBase; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.systemtest.utils.TestUtils; import org.slf4j.Logger; @@ -419,13 +418,4 @@ public static ExecutionResultData runOnClusterWithoutLogger(String... args) { command.addAll(Arrays.asList(args)); return Exec.execute(command, ONE_MINUTE_TIMEOUT, false); } - - public static void awaitRollout(TimeoutBudget budget, String namespace, String deploymentName) { - TestUtils.waitUntilCondition(String.format("Wait for deployment %s in namespace %s rollout to complete", deploymentName, namespace), waitPhase -> { - ExecutionResultData rollout = Exec.execute(Arrays.asList(ITestBase.kubernetes.getCluster().getKubeCmd(), "rollout", - "status", "deployment", deploymentName, - "--namespace", namespace), true); - return rollout.getRetCode(); - }, budget); - } } diff --git a/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java b/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java index 89e5685ab11..8b3726ebe69 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/resources/CliOutputData.java @@ -172,7 +172,7 @@ public static class AddressSpaceRow extends CliDataRow { private String phase; private String status; - AddressSpaceRow(String[] parsedData) { + public AddressSpaceRow(String[] parsedData) { expectColumns(7, parsedData); this.name = parsedData[0]; this.type = parsedData[1]; @@ -242,7 +242,7 @@ public static class AddressRow extends CliDataRow { private String phase; private String status; - AddressRow(String[] parsedData) { + public AddressRow(String[] parsedData) { expectColumns(8, parsedData); this.name = parsedData[0]; this.address = parsedData[1]; @@ -317,7 +317,7 @@ public static class UserRow extends CliDataRow { private String username; private String phase; - UserRow(String[] parsedData) { + public UserRow(String[] parsedData) { expectColumns(5, parsedData); this.name = parsedData[0]; this.username = parsedData[1]; diff --git a/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java b/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java index 21dd1738478..9739c209941 100644 --- a/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java +++ b/systemtests/src/main/java/io/enmasse/systemtest/utils/UserUtils.java @@ -5,13 +5,9 @@ package io.enmasse.systemtest.utils; import com.fasterxml.jackson.databind.ObjectMapper; -import io.enmasse.address.model.AddressSpace; import io.enmasse.address.model.Phase; import io.enmasse.systemtest.UserCredentials; import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.manager.IsolatedIoTManager; -import io.enmasse.systemtest.manager.IsolatedResourcesManager; -import io.enmasse.systemtest.manager.ResourceManager; import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.time.TimeoutBudget; import io.enmasse.user.model.v1.DoneableUser; @@ -108,8 +104,4 @@ public static String base64ToPassword(String password) { public static UserCredentials getCredentialsFromUser(User user) { return new UserCredentials(user.getSpec().getUsername(), base64ToPassword(user.getSpec().getAuthentication().getPassword())); } - - public static boolean userExist(AddressSpace addressSpace, String username) { - return IsolatedResourcesManager.getInstance().getUser(addressSpace, username) != null; - } } diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java index bf5dedb2750..9600fccbf27 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/bases/TestBase.java @@ -5,70 +5,25 @@ package io.enmasse.systemtest.bases; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import javax.jms.DeliveryMode; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; - -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.message.Message; -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.extension.ExtendWith; -import org.slf4j.Logger; - -import com.google.common.collect.Ordering; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; import io.enmasse.systemtest.Environment; import io.enmasse.systemtest.IndicativeSentences; +import io.enmasse.systemtest.TestTag; import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.info.TestInfo; +import io.enmasse.systemtest.clients.ClientUtils; import io.enmasse.systemtest.listener.JunitCallbackListener; -import io.enmasse.systemtest.logs.GlobalLogCollector; import io.enmasse.systemtest.messaginginfra.ResourceManager; -import io.enmasse.systemtest.mqtt.MqttUtils; import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.JmsProvider; -import io.enmasse.systemtest.utils.TestUtils; +import io.enmasse.systemtest.platform.Kubernetes; import io.enmasse.systemtest.utils.ThrowingCallable; import io.enmasse.systemtest.utils.ThrowingConsumer; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.DisplayNameGeneration; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.LinkedList; +import java.util.List; /** * Base class for all tests @@ -76,23 +31,25 @@ @ExtendWith(JunitCallbackListener.class) @DisplayNameGeneration(IndicativeSentences.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) -public abstract class TestBase implements ITestBase, ITestSeparator { +@Tag(TestTag.SYSTEMTEST) +public abstract class TestBase implements ITestSeparator { + ClientUtils clientUtils = new ClientUtils(); + protected static final Kubernetes kubernetes = Kubernetes.getInstance(); protected static final UserCredentials clusterUser = new UserCredentials(KubeCMDClient.getOCUser()); protected static final Environment environment = Environment.getInstance(); - protected static final GlobalLogCollector logCollector = new GlobalLogCollector(kubernetes, environment.testLogDir()); - protected io.enmasse.systemtest.manager.ResourceManager resourcesManager; - protected UserCredentials defaultCredentials = null; - protected UserCredentials managementCredentials = null; - protected ResourceManager infraResourceManager = ResourceManager.getInstance(); + protected UserCredentials defaultCredentials = environment.getDefaultCredentials(); + protected UserCredentials managementCredentials = environment.getManagementCredentials(); + protected ResourceManager resourceManager = ResourceManager.getInstance(); + protected List cleanup = new LinkedList<>(); /** * Close any provided resource at the end of test, by calling the cleaner. * - * @param The type of the closable. + * @param The type of the closable. * @param resource The closable to close. - * @param cleaner The cleaner, which will be called. + * @param cleaner The cleaner, which will be called. * @return The input value, for chained calls. */ protected T cleanup(final T resource, final ThrowingConsumer cleaner) { @@ -103,36 +60,16 @@ protected T cleanup(final T resource, final ThrowingConsumer cleaner) { /** * Close an {@link AutoCloseable} at the end of the test. * - * @param The type of the closable. + * @param The type of the closable. * @param closeable The closable to close. * @return The input value, for chained calls. */ - protected T cleanup (final T closeable) { + protected T cleanup(final T closeable) { return cleanup(closeable, AutoCloseable::close); } - @BeforeEach - public void initTest() throws Exception { - LOGGER.info("Test init"); - resourcesManager = getResourceManager(); - if (TestInfo.getInstance().isTestShared()) { - defaultCredentials = environment.getSharedDefaultCredentials(); - managementCredentials = environment.getSharedManagementCredentials(); - resourcesManager.setAddressSpacePlan(getDefaultAddressSpacePlan()); - resourcesManager.setAddressSpaceType(getAddressSpaceType().toString()); - resourcesManager.setDefaultAddSpaceIdentifier(getDefaultAddrSpaceIdentifier()); - if (resourcesManager.getSharedAddressSpace() == null) { - resourcesManager.setup(); - } - } else { - defaultCredentials = environment.getDefaultCredentials(); - managementCredentials = environment.getManagementCredentials(); - resourcesManager.setup(); - } - } - @AfterEach - private void cleanup() throws Exception { + void cleanup() throws Exception { Exception exception = null; for (ThrowingCallable cleanup : this.cleanup) { try { @@ -151,243 +88,7 @@ private void cleanup() throws Exception { } } - //================================================================================================ - //======================================= Help methods =========================================== - //================================================================================================ - - protected void waitForBrokerReplicas(AddressSpace addressSpace, Address destination, int expectedReplicas) throws - Exception { - TimeoutBudget budget = new TimeoutBudget(10, TimeUnit.MINUTES); - TestUtils.waitForNBrokerReplicas(addressSpace, expectedReplicas, true, destination, budget, 5000); - } - - protected void waitForRouterReplicas(AddressSpace addressSpace, int expectedReplicas) throws - Exception { - TimeoutBudget budget = new TimeoutBudget(3, TimeUnit.MINUTES); - Map labels = new HashMap<>(); - labels.put("name", "qdrouterd"); - labels.put("infraUuid", AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace)); - TestUtils.waitForNReplicas(expectedReplicas, kubernetes.getInfraNamespace(), labels, budget); - } - - protected void waitForPodsToTerminate(List uids) throws Exception { - LOGGER.info("Waiting for following pods to be deleted {}", uids); - assertWaitForValue(true, () -> (kubernetes.listPods(kubernetes.getInfraNamespace()).stream() - .noneMatch(pod -> uids.contains(pod.getMetadata().getUid()))), new TimeoutBudget(2, TimeUnit.MINUTES)); - } - - protected void logWithSeparator(Logger logger, String... messages) { - logger.info("--------------------------------------------------------------------------------"); - for (String message : messages) { - logger.info(message); - } - } - - protected List extractBodyAsString(Future> msgs) throws Exception { - return msgs.get(1, TimeUnit.MINUTES).stream().map(m -> (String) ((AmqpValue) m.getBody()).getValue()).collect(Collectors.toList()); - } - - //================================================================================================ - //==================================== Asserts methods =========================================== - //================================================================================================ - - protected static void assertSimpleMQTTSendReceive(Address dest, IMqttClient client, int msgCount) throws Exception { - List messages = IntStream.range(0, msgCount).boxed().map(i -> { - MqttMessage m = new MqttMessage(); - m.setPayload(String.format("mqtt-simple-send-receive-%s", i).getBytes(StandardCharsets.UTF_8)); - m.setQos(1); - return m; - }).collect(Collectors.toList()); - - List> receiveFutures = MqttUtils.subscribeAndReceiveMessages(client, dest.getSpec().getAddress(), messages.size(), 1); - List> publishFutures = MqttUtils.publish(client, dest.getSpec().getAddress(), messages); - - int publishCount = MqttUtils.awaitAndReturnCode(publishFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages published", - publishCount, is(messages.size())); - - int receivedCount = MqttUtils.awaitAndReturnCode(receiveFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages received", - receivedCount, is(messages.size())); - } - - protected > void assertSorted(String message, Iterable list) throws Exception { - assertSorted(message, list, false); - } - - protected void assertSorted(String message, Iterable list, Comparator comparator) throws Exception { - assertSorted(message, list, false, comparator); - } - - protected > void assertSorted(String message, Iterable list, boolean reverse) { - LOGGER.info("Assert sort reverse: " + reverse); - if (!reverse) { - assertTrue(Ordering.natural().isOrdered(list), message); - } else { - assertTrue(Ordering.natural().reverse().isOrdered(list), message); - } - } - - protected void assertSorted(String message, Iterable list, boolean reverse, Comparator comparator) { - LOGGER.info("Assert sort reverse: " + reverse); - if (!reverse) { - assertTrue(Ordering.from(comparator).isOrdered(list), message); - } else { - assertTrue(Ordering.from(comparator).reverse().isOrdered(list), message); - } - } - - protected void assertWaitForValue(T expected, Callable fn, TimeoutBudget budget) throws Exception { - T got = null; - LOGGER.info("waiting for expected value '{}' ...", expected); - while (budget.timeLeft() >= 0) { - got = fn.call(); - if (Objects.equals(expected, got)) { - return; - } - Thread.sleep(100); - } - fail(String.format("Incorrect result value! expected: '%s', got: '%s'", expected, Objects.requireNonNull(got))); - } - - protected static void assertDefaultEnabled(final Boolean enabled) { - if (enabled != null && !Boolean.TRUE.equals(enabled)) { - fail("Default value must be 'null' or 'true'"); - } - } - - protected void assertConcurentMessaging(List
dest, List users, String destNamePrefix, int customerIndex, int messageCount) throws Exception { - ArrayList clients = new ArrayList<>(users.size()); - String sufix = AddressSpaceUtils.isBrokered(resourcesManager.getSharedAddressSpace()) ? "#" : "*"; - users.forEach((user) -> { - try { - resourcesManager.createOrUpdateUser(resourcesManager.getSharedAddressSpace(), - UserUtils.createUserResource(user) - .editSpec() - .withAuthorization(Collections.singletonList( - new UserAuthorizationBuilder() - .withAddresses(String.format("%s.%s.%s", destNamePrefix, customerIndex, sufix)) - .withOperations(Operation.send, Operation.recv).build())) - .endSpec() - .done()); - AmqpClient queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(); - queueClient.getConnectOptions().setCredentials(user); - clients.add(queueClient); - } catch (Exception e) { - e.printStackTrace(); - } - }); - - AddressUtils.waitForDestinationsReady(dest.toArray(new Address[0])); - //start sending messages - int everyN = 3; - for (AmqpClient client : clients) { - for (int i = 0; i < dest.size(); i++) { - if (i % everyN == 0) { - Future sent = client.sendMessages(dest.get(i).getSpec().getAddress(), TestUtils.generateMessages(messageCount)); - //wait for messages sent - assertEquals(messageCount, sent.get(1, TimeUnit.MINUTES), - "Incorrect count of messages send"); - } - } - } - - //receive messages - for (AmqpClient client : clients) { - for (int i = 0; i < dest.size(); i++) { - if (i % everyN == 0) { - Future> received = client.recvMessages(dest.get(i).getSpec().getAddress(), messageCount); - //wait for messages received - assertEquals(messageCount, received.get(1, TimeUnit.MINUTES).size(), - "Incorrect count of messages received"); - } - } - client.close(); - } - } - - protected void assertSendReceiveLargeMessageQueue(JmsProvider jmsProvider, double sizeInMB, Address dest, int count) throws Exception { - assertSendReceiveLargeMessageQueue(jmsProvider, sizeInMB, dest, count, DeliveryMode.NON_PERSISTENT); - } - - protected void assertSendReceiveLargeMessageQueue(JmsProvider jmsProvider, double sizeInMB, Address dest, int count, int mode) throws Exception { - int size = (int) (sizeInMB * 1024 * 1024); - - Session session = jmsProvider.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - javax.jms.Queue testQueue = (javax.jms.Queue) jmsProvider.getDestination(dest.getSpec().getAddress()); - List messages = jmsProvider.generateMessages(session, count, size); - - MessageProducer sender = session.createProducer(testQueue); - MessageConsumer receiver = session.createConsumer(testQueue); - - assertSendReceiveLargeMessage(jmsProvider, sender, receiver, sizeInMB, mode, count, messages); - - } - - protected void assertSendReceiveLargeMessageTopic(JmsProvider jmsProvider, double sizeInMB, Address dest, int count) throws Exception { - assertSendReceiveLargeMessageTopic(jmsProvider, sizeInMB, dest, count, DeliveryMode.NON_PERSISTENT); - } - - protected void assertSendReceiveLargeMessageTopic(JmsProvider jmsProvider, double sizeInMB, Address dest, int count, int mode) throws Exception { - int size = (int) (sizeInMB * 1024 * 1024); - - Session session = jmsProvider.getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); - javax.jms.Topic testTopic = (javax.jms.Topic) jmsProvider.getDestination(dest.getSpec().getAddress()); - List messages = jmsProvider.generateMessages(session, count, size); - - MessageProducer sender = session.createProducer(testTopic); - MessageConsumer receiver = session.createConsumer(testTopic); - - assertSendReceiveLargeMessage(jmsProvider, sender, receiver, sizeInMB, mode, count, messages); - session.close(); - sender.close(); - receiver.close(); - } - - private void assertSendReceiveLargeMessage(JmsProvider jmsProvider, MessageProducer sender, MessageConsumer receiver, double sizeInMB, int mode, int count, List messages) { - List recvd; - - jmsProvider.sendMessages(sender, messages, mode, javax.jms.Message.DEFAULT_PRIORITY, javax.jms.Message.DEFAULT_TIME_TO_LIVE); - LOGGER.info("{}MB {} message sent", sizeInMB, mode == DeliveryMode.PERSISTENT ? "durable" : "non-durable"); - - recvd = jmsProvider.receiveMessages(receiver, count, 2000); - assertThat("Wrong count of received messages", recvd.size(), Matchers.is(count)); - LOGGER.info("{}MB {} message received", sizeInMB, mode == DeliveryMode.PERSISTENT ? "durable" : "non-durable"); - } - - protected void assertAddressApi(AddressSpace addressSpace, Address d1, Address d2) throws Exception { - List destinationsNames = Arrays.asList(d1.getSpec().getAddress(), d2.getSpec().getAddress()); - resourcesManager.setAddresses(d1); - resourcesManager.appendAddresses(d2); - - //d1, d2 - List response = AddressUtils.getAddresses(addressSpace).stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList()); - assertThat("Rest api does not return all addresses", response, is(destinationsNames)); - LOGGER.info("addresses {} successfully created", Arrays.toString(destinationsNames.toArray())); - - //get specific address d2 - Address res = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(d2.getMetadata().getName()).get(); - assertThat("Rest api does not return specific address", res.getSpec().getAddress(), is(d2.getSpec().getAddress())); - - resourcesManager.deleteAddresses(d1); - - //d2 - response = AddressUtils.getAddresses(addressSpace).stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList()); - assertThat("Rest api does not return right addresses", response, is(destinationsNames.subList(1, 2))); - LOGGER.info("address {} successfully deleted", d1.getSpec().getAddress()); - - resourcesManager.deleteAddresses(d2); - - //empty - List
listRes = AddressUtils.getAddresses(addressSpace); - assertThat("Rest api returns addresses", listRes, is(Collections.emptyList())); - LOGGER.info("addresses {} successfully deleted", d2.getSpec().getAddress()); - - resourcesManager.setAddresses(d1, d2); - resourcesManager.deleteAddresses(d1, d2); - - listRes = AddressUtils.getAddresses(addressSpace); - assertThat("Rest api returns addresses", listRes, is(Collections.emptyList())); - LOGGER.info("addresses {} successfully deleted", Arrays.toString(destinationsNames.toArray())); + protected ClientUtils getClientUtils() { + return clientUtils; } } diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java deleted file mode 100644 index 1abcb750b99..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/authz/AuthorizationTestBase.java +++ /dev/null @@ -1,521 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.authz; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.UnauthorizedAccessException; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import io.vertx.proton.sasl.SaslSystemException; -import org.apache.qpid.proton.message.Message; -import org.slf4j.Logger; - -import javax.security.sasl.AuthenticationException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class AuthorizationTestBase extends TestBase implements ITestBaseShared { - - private static Logger log = CustomLogger.getLogger(); - - private Address queue; - private Address topic; - private Address anycast; - private Address multicast; - private List
addresses; - - private void initAddresses() throws Exception { - queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz_queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("authz_queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("authz-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - anycast = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-anycast")) - .endMetadata() - .withNewSpec() - .withType("anycast") - .withAddress("authz-anycast") - .withPlan(DestinationPlan.STANDARD_SMALL_ANYCAST) - .endSpec() - .build(); - - multicast = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "authz-multicast")) - .endMetadata() - .withNewSpec() - .withType("multicast") - .withAddress("authz-multicast") - .withPlan(DestinationPlan.STANDARD_SMALL_MULTICAST) - .endSpec() - .build(); - - addresses = new ArrayList<>(); - addresses.add(queue); - addresses.add(topic); - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - addresses.add(anycast); - addresses.add(multicast); - } - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - } - - protected void doTestSendAuthz() throws Exception { - initAddresses(); - UserCredentials allowedUser = new UserCredentials("sender", "senderPa55"); - UserCredentials noAllowedUser = new UserCredentials("notallowedsender", "nobodyPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder().withAddresses("*").withOperations(Operation.send).build())) - .endSpec() - .done()); - Thread.sleep(100); - assertSend(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(addresses.stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList())) - .withOperations(Operation.send).build())) - .endSpec() - .done()); - Thread.sleep(100); - assertSend(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser).done()); - assertCannotSend(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertCannotSend(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - } - - protected void doTestReceiveAuthz() throws Exception { - initAddresses(); - UserCredentials allowedUser = new UserCredentials("receiver", "receiverPa55"); - UserCredentials noAllowedUser = new UserCredentials("notallowedreceiver", "nobodyPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder().withAddresses("*").withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertReceive(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(allowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(addresses.stream().map(address -> address.getSpec().getAddress()).collect(Collectors.toList())) - .withOperations(Operation.recv).build())) - .endSpec() - .done()); - assertReceive(allowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), allowedUser.getUsername()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(noAllowedUser) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.send).build())) - .endSpec() - .done()); - assertCannotReceive(noAllowedUser); - resourcesManager.removeUser(getSharedAddressSpace(), noAllowedUser.getUsername()); - } - - protected void doTestUserPermissionAfterRemoveAuthz() throws Exception { - initAddresses(); - UserCredentials user = new UserCredentials("pepa", "pepaPa55"); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(user) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withOperations(Operation.recv) - .withAddresses("*").build())) - .endSpec() - .done()); - assertReceive(user); - resourcesManager.removeUser(getSharedAddressSpace(), user.getUsername()); - Thread.sleep(5000); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), UserUtils.createUserResource(user) - .editSpec() - .withAuthorization( - Collections.singletonList(new UserAuthorizationBuilder() - .withOperations(Operation.recv) - .withAddresses("pepa_address").build())) - .endSpec() - .done()); - assertCannotReceive(user); - resourcesManager.removeUser(getSharedAddressSpace(), user.getUsername()); - } - - protected void doTestSendAuthzWithWIldcards() throws Exception { - List
addresses = getAddressesWildcard(getSharedAddressSpace()); - List users = createUsersWildcard(getSharedAddressSpace(), Operation.send); - - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - - for (User user : users) { - for (Address destination : addresses) { - assertSendWildcard(user, destination); - } - resourcesManager.removeUser(getSharedAddressSpace(), user.getSpec().getUsername()); - } - } - - protected void doTestReceiveAuthzWithWIldcards() throws Exception { - List
addresses = getAddressesWildcard(getSharedAddressSpace()); - List users = createUsersWildcard(getSharedAddressSpace(), Operation.recv); - - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - - for (User user : users) { - for (Address destination : addresses) { - assertReceiveWildcard(user, destination); - } - resourcesManager.removeUser(getSharedAddressSpace(), user.getSpec().getUsername()); - } - } - - //=========================================================================================================== - // Help methods - //=========================================================================================================== - - private void assertSendWildcard(User user, Address destination) throws Exception { - List addresses = user.getSpec().getAuthorization().stream() - .map(authz -> authz.getAddresses().stream()) - .flatMap(Stream::distinct) - .collect(Collectors.toList()); - - UserCredentials credentials = UserUtils.getCredentialsFromUser(user); - if (addresses.stream().filter(address -> destination.getSpec().getAddress().contains(address.replace("*", ""))).count() > 0) { - assertTrue(canSend(destination, credentials), - String.format("Authz failed, user %s cannot send message to destination %s", credentials, - destination.getSpec().getAddress())); - } else { - assertFalse(canSend(destination, credentials), - String.format("Authz failed, user %s can send message to destination %s", credentials, - destination.getSpec().getAddress())); - } - } - - private void assertReceiveWildcard(User user, Address destination) throws Exception { - List addresses = user.getSpec().getAuthorization().stream() - .map(authz -> authz.getAddresses().stream()) - .flatMap(Stream::distinct) - .collect(Collectors.toList()); - - UserCredentials credentials = UserUtils.getCredentialsFromUser(user); - if (addresses.stream().filter(address -> destination.getSpec().getAddress().contains(address.replace("*", ""))).count() > 0) { - assertTrue(canReceive(destination, credentials), - String.format("Authz failed, user %s cannot receive message from destination %s", credentials, - destination.getSpec().getAddress())); - } else { - assertFalse(canReceive(destination, credentials), - String.format("Authz failed, user %s can receive message from destination %s", credentials, - destination.getSpec().getAddress())); - } - } - - private void assertSend(UserCredentials credentials) throws Exception { - log.info("Testing if client is authorized to send messages"); - String message = String.format("Authz failed, user %s cannot send message", credentials); - assertTrue(canSend(queue, credentials), message); - assertTrue(canSend(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertTrue(canSend(multicast, credentials), message); - assertTrue(canSend(anycast, credentials), message); - } - } - - private void assertCannotSend(UserCredentials credentials) throws Exception { - log.info("Testing if client is NOT authorized to send messages"); - String message = String.format("Authz failed, user %s can send message", credentials); - assertFalse(canSend(queue, credentials), message); - assertFalse(canSend(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertFalse(canSend(multicast, credentials), message); - assertFalse(canSend(anycast, credentials), message); - } - } - - private void assertReceive(UserCredentials credentials) throws Exception { - log.info("Testing if client is authorized to receive messages"); - String message = String.format("Authz failed, user %s cannot receive message", credentials); - assertTrue(canReceive(queue, credentials), message); - assertTrue(canReceive(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertTrue(canReceive(multicast, credentials), message); - assertTrue(canReceive(anycast, credentials), message); - } - } - - private void assertCannotReceive(UserCredentials credentials) throws Exception { - log.info("Testing if client is NOT authorized to receive messages"); - String message = String.format("Authz failed, user %s can receive message", credentials); - assertFalse(canReceive(queue, credentials), message); - assertFalse(canReceive(topic, credentials), message); - - if (getAddressSpaceType() == AddressSpaceType.STANDARD) { - assertFalse(canReceive(multicast, credentials), message); - assertFalse(canReceive(anycast, credentials), message); - } - } - - private boolean canSend(Address destination, UserCredentials credentials) throws Exception { - logWithSeparator(log, - String.format("Try send message under user %s from %s %s", credentials, destination.getSpec().getType(), destination.getSpec().getAddress()), - String.format("***** Try to open sender client under user %s", credentials), - String.format("***** Try to open receiver client under user %s", defaultCredentials)); - AmqpClient sender = createClient(destination, credentials); - AmqpClient receiver = createClient(destination, defaultCredentials); - logWithSeparator(log); - return canAuth(sender, receiver, destination, true); - } - - private boolean canReceive(Address destination, UserCredentials credentials) throws Exception { - logWithSeparator(log, - String.format("Try receive message under user %s from %s %s", credentials, destination.getSpec().getType(), destination.getSpec().getAddress()), - String.format("***** Try to open sender client under user %s", defaultCredentials), - String.format("***** Try to open receiver client under user %s", credentials)); - - AmqpClient sender = createClient(destination, defaultCredentials); - AmqpClient receiver = createClient(destination, credentials); - logWithSeparator(log); - return canAuth(sender, receiver, destination, false); - } - - private boolean canAuth(AmqpClient sender, AmqpClient receiver, Address destination, boolean checkSender) throws Exception { - try { - log.info("Staring receiver for " + destination.getSpec().getAddress()); - Future> received = receiver.recvMessages(destination.getSpec().getAddress(), 1); - - log.info("Staring sender for " + destination.getSpec().getAddress()); - Future sent = sender.sendMessages(destination.getSpec().getAddress(), Collections.singletonList("msg1")); - - if (checkSender) { - int numSent = sent.get(1, TimeUnit.MINUTES); - log.info("Sent {}", numSent); - int numReceived = received.get(1, TimeUnit.MINUTES).size(); - return numSent == numReceived; - } else { - int numReceived = received.get(1, TimeUnit.MINUTES).size(); - int numSent = sent.get(1, TimeUnit.MINUTES); - return numSent == numReceived; - } - } catch (ExecutionException | SecurityException | UnauthorizedAccessException ex) { - Throwable cause = ex; - if (ex instanceof ExecutionException) { - cause = ex.getCause(); - } - - if (cause instanceof SecurityException || cause instanceof SaslSystemException || cause instanceof AuthenticationException || cause instanceof UnauthorizedAccessException) { - log.info("canAuth {} ({}): {}", destination.getSpec().getAddress(), destination.getSpec().getType(), ex.getMessage()); - return false; - } else { - log.warn("canAuth {} ({}) exception", destination.getSpec().getAddress(), destination.getSpec().getType(), ex); - throw ex; - } - } finally { - sender.close(); - receiver.close(); - } - } - - private AmqpClient createClient(Address dest, UserCredentials credentials) throws Exception { - AmqpClient client = null; - - switch (dest.getSpec().getType()) { - case "queue": - case "anycast": - client = getAmqpClientFactory().createQueueClient(getSharedAddressSpace()); - break; - case "topic": - client = getAmqpClientFactory().createTopicClient(getSharedAddressSpace()); - break; - case "multicast": - client = getAmqpClientFactory().createBroadcastClient(getSharedAddressSpace()); - break; - } - - Objects.requireNonNull(client).getConnectOptions().setCredentials(credentials); - return client; - } - - protected List
getAddressesWildcard(AddressSpace addressspace) { - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "queue/1234")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue/1234") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address queue2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "queue/ABCD")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue/ABCD") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "topic/2345")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic/2345") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - Address topic2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, "topic/ABCD")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic/ABCD") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - return Arrays.asList(queue, queue2, topic, topic2); - } - - protected List createUsersWildcard(AddressSpace addressSpace, Operation operation) throws - Exception { - List users = new ArrayList<>(); - users.add(UserUtils.createUserResource(new UserCredentials("user1", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user2", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("queue/*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user3", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("topic/*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user4", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("queueA*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - users.add(UserUtils.createUserResource(new UserCredentials("user5", "password")) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("topicA*") - .withOperations(operation) - .build())) - .endSpec() - .done()); - - for (User user : users) { - resourcesManager.createOrUpdateUser(addressSpace, user); - } - return users; - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java deleted file mode 100644 index 9907442bd60..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/bridging/BridgingBase.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.bridging; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorAddressRuleBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorCredentials; -import io.enmasse.address.model.AddressSpaceSpecConnectorCredentialsBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorEndpointBuilder; -import io.enmasse.address.model.AddressSpaceSpecConnectorTls; -import io.enmasse.address.model.AddressSpaceSpecConnectorTlsBuilder; -import io.enmasse.address.model.StringOrSecretSelectorBuilder; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpConnectOptions; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestIsolatedStandard; -import io.enmasse.systemtest.certs.BrokerCertBundle; -import io.enmasse.systemtest.certs.openssl.OpenSSLUtil; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder; -import io.vertx.proton.ProtonClientOptions; -import io.vertx.proton.ProtonQoS; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import java.nio.file.Path; -import java.util.Base64; - -public abstract class BridgingBase extends TestBase implements ITestIsolatedStandard { - - private static Logger log = CustomLogger.getLogger(); - - protected static final String REMOTE_NAME = "remote1"; - - protected final String remoteBrokerName = "amq-broker"; - protected final String remoteBrokerNamespace = "systemtests-external-broker"; - protected final String remoteBrokerUsername = "test-user"; - protected final String remoteBrokerPassword = "test-password"; - protected Endpoint clientBrokerEndpoint; - protected Endpoint clientBrokerEndpointExternal; - protected Endpoint remoteBrokerEndpoint; - protected Endpoint remoteBrokerEndpointSSL; - protected Endpoint remoteBrokerEndpointMutualTLS; - protected BrokerCertBundle certBundle; - - @BeforeEach - void deployBroker() throws Exception { - String serviceName = String.format("%s.%s.svc.cluster.local", remoteBrokerName, remoteBrokerNamespace); - certBundle = OpenSSLUtil.createBrokerCertBundle(serviceName); - SystemtestsKubernetesApps.deployAMQBroker(remoteBrokerNamespace, remoteBrokerName, remoteBrokerUsername, remoteBrokerPassword, certBundle); - remoteBrokerEndpoint = new Endpoint(serviceName, 5672); - remoteBrokerEndpointSSL = new Endpoint(serviceName, 5671); - remoteBrokerEndpointMutualTLS = new Endpoint(serviceName, 55671); - clientBrokerEndpointExternal = Kubernetes.getInstance().getExternalEndpoint(remoteBrokerName, remoteBrokerNamespace); - clientBrokerEndpoint = remoteBrokerEndpoint; - log.info("Broker endpoint: {}", remoteBrokerEndpoint); - log.info("Broker SSL endpoint: {}", remoteBrokerEndpointSSL); - log.info("Client broker endpoint: {}", clientBrokerEndpoint); - } - - @AfterEach - void undeployBroker(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - Path path = TestUtils.getFailedTestLogsPath(context); - SystemtestsKubernetesApps.collectAMQBrokerLogs(path, remoteBrokerNamespace); - } - SystemtestsKubernetesApps.deleteAMQBroker(remoteBrokerNamespace, remoteBrokerName); - } - - protected void scaleDownBroker() throws Exception { - log.info("Scaling down broker"); - SystemtestsKubernetesApps.scaleDownDeployment(remoteBrokerNamespace, remoteBrokerName); - } - - protected void scaleUpBroker() throws Exception { - log.info("Scaling up broker"); - SystemtestsKubernetesApps.scaleUpDeployment(remoteBrokerNamespace, remoteBrokerName); - } - - protected AddressSpace createAddressSpace(String name, String addressRule, AddressSpaceSpecConnectorTls tlsSettings, AddressSpaceSpecConnectorCredentials credentials) throws Exception { - var endpoint = tlsSettings != null ? tlsSettings.getClientCert() != null ? remoteBrokerEndpointMutualTLS : remoteBrokerEndpointSSL : remoteBrokerEndpoint; - var connectorBuilder = new AddressSpaceSpecConnectorBuilder() - .withName(REMOTE_NAME) - .addToEndpointHosts(new AddressSpaceSpecConnectorEndpointBuilder() - .withHost(endpoint.getHost()) - .withPort(endpoint.getPort()) - .build()) - .addToAddresses(new AddressSpaceSpecConnectorAddressRuleBuilder() - .withName("queuesrule") - .withPattern(addressRule) - .build()); - - if (tlsSettings != null) { - connectorBuilder.withTls(tlsSettings); - } - - //only set credentials when mutual tls isn't configured - if (tlsSettings == null || tlsSettings.getClientCert() == null) { - if (credentials == null) { - Assertions.fail("Connector wrongly configured, missing connector credentials"); - } - connectorBuilder.withCredentials(credentials); - } - - AddressSpace space = new AddressSpaceBuilder() - .withNewMetadata() - .withNamespace(remoteBrokerNamespace) - .withName(name) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withConnectors(connectorBuilder.build()) - .endSpec() - .build(); - resourcesManager.createAddressSpace(space); - AddressSpaceUtils.waitForAddressSpaceConnectorsReady(space); - return space; - } - - protected AmqpClient createClientToRemoteBroker() { - ProtonClientOptions clientOptions = new ProtonClientOptions(); - clientOptions.setSsl(true); - clientOptions.setTrustAll(true); - clientOptions.setHostnameVerificationAlgorithm(""); - - AmqpConnectOptions connectOptions = new AmqpConnectOptions() - .setTerminusFactory(new QueueTerminusFactory()) - .setEndpoint(clientBrokerEndpointExternal) - .setProtonClientOptions(clientOptions) - .setQos(ProtonQoS.AT_LEAST_ONCE) - .setUsername(remoteBrokerUsername) - .setPassword(remoteBrokerPassword); - return getAmqpClientFactory().createClient(connectOptions); - } - - protected ExternalMessagingClient createOnClusterClientToRemoteBroker(AbstractClient client, int messageCount) { - return new ExternalMessagingClient(false) - .withMessagingRoute(clientBrokerEndpoint) - .withMessageBody("msg no. %d") - .withCount(messageCount) - .withClientEngine(client) - .withAdditionalArgument(ClientArgument.CONN_AUTH_MECHANISM, "PLAIN") - .withCredentials(remoteBrokerUsername, remoteBrokerPassword); - } - - protected AddressSpaceSpecConnectorCredentials defaultCredentials() { - return new AddressSpaceSpecConnectorCredentialsBuilder() - .withNewUsername() - .withValue(remoteBrokerUsername) - .endUsername() - .withNewPassword() - .withValue(remoteBrokerPassword) - .endPassword() - .build(); - } - - protected AddressSpaceSpecConnectorCredentials credentialsInSecret() { - return new AddressSpaceSpecConnectorCredentialsBuilder() - .withNewUsername() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("user") - .build()) - .endUsername() - .withNewPassword() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("password") - .build()) - .endPassword() - .build(); - } - - protected AddressSpaceSpecConnectorTls defaultTls() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getCaCert())) - .build()) - .build(); - } - - protected AddressSpaceSpecConnectorTls tlsInSecret() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValueFromSecret(new SecretKeySelectorBuilder() - .withName(remoteBrokerName) - .withKey("ca.crt") - .build()) - .build()) - .build(); - } - - protected AddressSpaceSpecConnectorTls defaultMutualTls() { - return new AddressSpaceSpecConnectorTlsBuilder() - .withCaCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getCaCert())) - .build()) - .withClientCert(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getClientCert())) - .build()) - .withClientKey(new StringOrSecretSelectorBuilder() - .withValue(Base64.getEncoder().encodeToString(certBundle.getClientKey())) - .build()) - .build(); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java deleted file mode 100644 index 531d19ec96c..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClientTestBase.java +++ /dev/null @@ -1,591 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.clients; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ClientType; -import io.enmasse.systemtest.annotations.ExternalClients; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.UserUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.function.Executable; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@ExternalClients -public abstract class ClientTestBase extends TestBase implements ITestBaseShared { - protected Path logPath = null; - private List clients; - - @BeforeEach - public void setUpClientBase(TestInfo info) { - clients = new ArrayList<>(); - String clientFolder = "clients_tests"; - logPath = environment.testLogDir().resolve( - Paths.get( - clientFolder, - info.getTestClass().get().getName(), - info.getDisplayName())); - } - - @AfterEach - public void teardownClient() { - if (clients != null) { - clients.forEach(AbstractClient::stop); - clients.clear(); - } - } - - private Endpoint getMessagingRoute(AddressSpace addressSpace, boolean websocket) throws Exception { - return websocket ? AddressSpaceUtils.getMessagingWssRoute(addressSpace) : AddressSpaceUtils.getMessagingRoute(addressSpace); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver) throws Exception { - doBasicMessageTest(sender, receiver, false); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver, boolean websocket) throws Exception { - clients.addAll(Arrays.asList(sender, receiver)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : "") - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : "") - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doRoundRobinReceiverTest(AbstractClient sender, AbstractClient receiver, AbstractClient receiver2) - throws Exception { - clients.addAll(Arrays.asList(sender, receiver, receiver2)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "round-robin" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("round-robin" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30); - - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount / 2) - .withTimeout(250); - - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(receiver2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount / 2) - .withTimeout(250); - - Future recResult = receiverClient1.runAsync(); - Future rec2Result = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(recResult.get(), "Receiver failed, expected return code 0"); - assertTrue(rec2Result.get(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - - assertAll( - () -> assertEquals(expectedMsgCount / 2, receiverClient1.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount / 2)), - () -> assertEquals(expectedMsgCount / 2, receiverClient2.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount / 2))); - } - - protected void doTopicSubscribeTest(AbstractClient sender, AbstractClient subscriber, AbstractClient subscriber2) throws Exception { - clients.addAll(Arrays.asList(sender, subscriber, subscriber2)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "topic-sub" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic-sub" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(subscriber) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(subscriber2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "MULTICAST"); - - Future recResult = receiverClient1.runAsync(); - Future recResult2 = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertAll( - () -> assertTrue(senderClient.run(), "Producer failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(recResult.get(), "Subscriber failed, expected return code 0"), - () -> assertTrue(recResult2.get(), "Subscriber failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient1.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)), - () -> assertEquals(expectedMsgCount, receiverClient2.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } - - protected void doMessageBrowseTest(AbstractClient sender, AbstractClient receiver_browse, AbstractClient receiver_receive) - throws Exception { - clients.addAll(Arrays.asList(sender, receiver_browse, receiver_receive)); - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "browse" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("browse" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient receiverClientBrowse = new ExternalMessagingClient() - .withClientEngine(receiver_browse) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "true"); - - ExternalMessagingClient receiverClientReceive = new ExternalMessagingClient() - .withClientEngine(receiver_receive) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "false"); - - assertAll( - () -> assertTrue(senderClient.run(), "Sender failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(receiverClientBrowse.run(), "Browse receiver failed, expected return code 0"), - () -> assertTrue(receiverClientReceive.run(), "Receiver failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClientBrowse.getMessages().size(), - String.format("Expected %d browsed messages", expectedMsgCount)), - () -> assertEquals(expectedMsgCount, receiverClientReceive.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } - - protected void doDrainQueueTest(AbstractClient sender, AbstractClient receiver) throws Exception { - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "drain" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("drain" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - clients.addAll(Arrays.asList(sender, receiver)); - int expectedMsgCount = 50; - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(0) - .withTimeout(10); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Drain receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doMessageSelectorQueueTest(AbstractClient sender, AbstractClient receiver) throws Exception { - int expectedMsgCount = 10; - - clients.addAll(Arrays.asList(sender, receiver)); - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "selector-queue" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("selector-queue" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(queue); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(queue) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~red") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~12.65") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "a~true") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "b~false") - .withMessageBody("msg no. %d"); - - //send messages - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(0) - .withCredentials(defaultCredentials) - .withAddress(queue) - .withAdditionalArgument(ClientArgument.RECV_BROWSE, "true"); - - //receiver with selector colour = red - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "colour = 'red'"); - final Executable executable = () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'colour = red'", expectedMsgCount)); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'colour = red' failed, expected return code 0"), - executable); - - //receiver with selector number > 12.5 - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "number > 12.5"); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'number > 12.5' failed, expected return code 0"), - executable); - - - //receiver with selector a AND b - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "a AND b"); - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'a AND b' failed, expected return code 0"), - () -> assertEquals(0, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'a AND b'", 0))); - - //receiver with selector a OR b - receiverClient.withAdditionalArgument(ClientArgument.RECV_BROWSE, "false"); - receiverClient.withAdditionalArgument(ClientArgument.SELECTOR, "a OR b"); - - assertAll( - () -> assertTrue(receiverClient.run(), "Receiver 'a OR b' failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages 'a OR b'", expectedMsgCount))); - } - - protected void doMessageSelectorTopicTest(AbstractClient sender, AbstractClient sender2, - AbstractClient subscriber, AbstractClient subscriber2) throws Exception { - clients.addAll(Arrays.asList(sender, sender2, subscriber, subscriber2)); - int expectedMsgCount = 5; - - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "selector-topic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("selector-topic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(topic); - - //set up senders - ExternalMessagingClient senderClient1 = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(topic) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~red") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~12.65") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "a~true") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "b~false") - .withTimeout(250) - .withMessageBody("msg no. %d"); - - ExternalMessagingClient senderClient2 = new ExternalMessagingClient() - .withClientEngine(sender2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withAddress(topic) - .withCredentials(defaultCredentials) - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "colour~blue") - .withAdditionalArgument(ClientArgument.MSG_PROPERTY, "number~11.65") - .withTimeout(250) - .withMessageBody("msg no. %d"); - - //set up subscriber1 - ExternalMessagingClient receiverClient1 = new ExternalMessagingClient() - .withClientEngine(subscriber) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withCredentials(defaultCredentials) - .withAddress(topic) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.SELECTOR, "colour = 'red' AND a"); - - //set up subscriber2 - ExternalMessagingClient receiverClient2 = new ExternalMessagingClient() - .withClientEngine(subscriber2) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(getSharedAddressSpace())) - .withCount(expectedMsgCount) - .withCredentials(defaultCredentials) - .withAddress(topic) - .withTimeout(250) - .withAdditionalArgument(ClientArgument.SELECTOR, "number < 12.5"); - - Future result1 = receiverClient1.runAsync(); - Future result2 = receiverClient2.runAsync(); - - receiverClient1.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - receiverClient2.getLinkAttachedProbe().get(15000, TimeUnit.MILLISECONDS); - - assertTrue(senderClient1.run(), "Sender failed, expected return code 0"); - assertTrue(senderClient2.run(), "Sender2 failed, expected return code 0"); - assertTrue(result1.get(), "Receiver 'colour = red' failed, expected return code 0"); - assertTrue(result2.get(), "Receiver 'number < 12.5' failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient1.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, senderClient2.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient1.getMessages().size(), - String.format("Expected %d received messages 'colour = red' AND a", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient2.getMessages().size(), - String.format("Expected %d received messages 'number < 12.5'", expectedMsgCount)); - } - - protected void doTestUserPermissions(AbstractClient sender, AbstractClient receiver) throws Exception { - int expectedMsgCount = 5; - UserCredentials publishCred = new UserCredentials("publisher", "publish"); - UserCredentials consumCred = new UserCredentials("consumer", "consume"); - createPublisherAndConsumer(publishCred, consumCred); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic" + ClientType.getAddressName(sender)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false)) - .withAddress(dest) - .withCredentials(publishCred) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withCredentials(consumCred) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false)) - .withAddress(dest) - .withCredentials(consumCred) - .withCount(expectedMsgCount) - .withTimeout(30) - .withCredentials(publishCred) - .withAdditionalArgument(ClientArgument.DEST_TYPE, "ANYCAST"); - - - assertAll( - () -> assertFalse(senderClient.run(), "Sender failed. Specified user is not allowed to write"), - () -> assertFalse(receiverClient.run(), "Receiver failed. Specified user is not allowed to read")); - - senderClient.withCredentials(publishCred); - - receiverClient.withCredentials(consumCred); - - assertTrue(senderClient.run(), "Sender failed, expected return code 0"); - assertTrue(receiverClient.run(), "Receiver failed, expected return code 0"); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - private void createPublisherAndConsumer(UserCredentials publishCred, UserCredentials consumCred) throws Exception { - User publisher = (UserUtils.createUserResource(publishCred) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.send) - .build())) - .endSpec() - .done()); - - User consumer = (UserUtils.createUserResource(consumCred) - .editSpec() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses("*") - .withOperations(Operation.recv) - .build())) - .endSpec() - .done()); - - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), publisher); - resourcesManager.createOrUpdateUser(getSharedAddressSpace(), consumer); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java deleted file mode 100644 index 1117b5dd400..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/clients/ClusterClientTestBase.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.clients; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.messagingclients.AbstractClient; -import io.enmasse.systemtest.messagingclients.ClientArgument; -import io.enmasse.systemtest.messagingclients.ClientType; -import io.enmasse.systemtest.annotations.ExternalClients; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.messagingclients.mqtt.PahoMQTTClientReceiver; -import io.enmasse.systemtest.messagingclients.mqtt.PahoMQTTClientSender; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; - -import java.util.concurrent.Future; - -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@ExternalClients -public abstract class ClusterClientTestBase extends TestBase implements ITestBaseShared { - - private Endpoint getMessagingRoute(AddressSpace addressSpace, boolean websocket, boolean ssl, boolean mqtt) throws Exception { - int port = ssl ? 5671 : 5672; - if (addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) && mqtt) { - port = ssl ? 8883 : 1883; - } - return new Endpoint(String.format("%s-%s.%s.svc.cluster.local", - (addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) && mqtt) ? "mqtt" : "messaging", - AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace), - environment.namespace()), - websocket && addressSpace.getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? 443 : port); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver) throws Exception { - doBasicMessageTest(sender, receiver, false); - } - - protected void doBasicMessageTest(AbstractClient sender, AbstractClient receiver, boolean websocket) throws Exception { - int expectedMsgCount = 10; - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "message-basic-" + ClientType.getAddressName(sender) + (websocket ? "-ws" : ""))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("message-basic-" + ClientType.getAddressName(sender) + (websocket ? "-ws" : "")) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket, true, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : ""); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), websocket, true, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(30) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET, websocket) - .withAdditionalArgument(ClientArgument.CONN_WEB_SOCKET_PROTOCOLS, getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? "binary" : ""); - - assertTrue(senderClient.run()); - assertTrue(receiverClient.run()); - - assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount)); - assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount)); - } - - protected void doMqttMessageTest() throws Exception { - int expectedMsgCount = 10; - AbstractClient sender = new PahoMQTTClientSender(); - AbstractClient receiver = new PahoMQTTClientReceiver(); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "basic-mqtt" + ClientType.getAddressName(sender))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("basic-mqtt" + ClientType.getAddressName(sender)) - .withPlan(getSharedAddressSpace().getSpec().getType().equals(AddressSpaceType.STANDARD.toString()) ? DestinationPlan.STANDARD_LARGE_TOPIC : getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - resourcesManager.setAddresses(dest); - - ExternalMessagingClient senderClient = new ExternalMessagingClient() - .withClientEngine(sender) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false, false, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withMessageBody("msg no. %d") - .withTimeout(30); - - ExternalMessagingClient receiverClient = new ExternalMessagingClient() - .withClientEngine(receiver) - .withMessagingRoute(getMessagingRoute(getSharedAddressSpace(), false, false, false)) - .withAddress(dest) - .withCredentials(defaultCredentials) - .withCount(expectedMsgCount) - .withTimeout(40); - - Future recResult = receiverClient.runAsync(); - Thread.sleep(20_000); - - assertAll( - () -> assertTrue(senderClient.run(), "Producer failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, senderClient.getMessages().size(), - String.format("Expected %d sent messages", expectedMsgCount))); - assertAll( - () -> assertTrue(recResult.get(), "Subscriber failed, expected return code 0"), - () -> assertEquals(expectedMsgCount, receiverClient.getMessages().size(), - String.format("Expected %d received messages", expectedMsgCount))); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java deleted file mode 100644 index 6e368c973d7..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/infra/InfraTestBase.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.infra; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.bases.ITestBase; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.infra.InfraConfiguration; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.User; -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.PersistentVolumeClaim; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.PodTemplateSpec; -import io.fabric8.kubernetes.api.model.ResourceRequirements; -import io.fabric8.kubernetes.api.model.Toleration; -import io.fabric8.kubernetes.api.model.storage.StorageClass; -import org.opentest4j.AssertionFailedError; -import org.slf4j.Logger; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class InfraTestBase extends TestBase implements ITestBase { - - private static final List resizingStorageProvisioners = Arrays.asList("kubernetes.io/aws-ebs", "kubernetes.io/gce-pd", - "kubernetes.io/azure-file", "kubernetes.io/azure-disk", "kubernetes.io/glusterfs", "kubernetes.io/cinder", - "kubernetes.io/portworx-volume", "kubernetes.io/rbd"); - private static Logger log = CustomLogger.getLogger(); - protected AddressPlan exampleAddressPlan; - protected AddressSpace exampleAddressSpace; - protected UserCredentials exampleUser = new UserCredentials("test", "test"); - - protected void assertBroker(InfraConfiguration brokerConfig) { - log.info("Checking broker infra"); - List brokerPods = TestUtils.listBrokerPods(kubernetes, exampleAddressSpace); - assertEquals(1, brokerPods.size()); - - Pod broker = brokerPods.stream().findFirst().get(); - - ResourceRequirements resources = broker.getSpec().getContainers().stream() - .filter(container -> container.getName().equals("broker")) - .findFirst() - .map(Container::getResources) - .get(); - assertEquals(brokerConfig.getMemory(), resources.getLimits().get("memory").getAmount(), - "Broker memory limit incorrect"); - assertEquals(brokerConfig.getMemory(), resources.getRequests().get("memory").getAmount(), - "Broker memory requests incorrect"); - if (brokerConfig.getCpu() != null) { - assertEquals(brokerConfig.getCpu(), resources.getLimits().get("cpu").getAmount(), - "Broker cpu limit incorrect"); - assertEquals(brokerConfig.getCpu(), resources.getRequests().get("cpu").getAmount(), - "Broker cpu requests incorrect"); - } - - if (brokerConfig.getBrokerStorage() != null) { - PersistentVolumeClaim brokerVolumeClaim = getBrokerPVCData(broker); - assertEquals(brokerConfig.getBrokerStorage(), brokerVolumeClaim.getSpec().getResources().getRequests().get("storage").getAmount(), - "Broker data storage request incorrect"); - } - - if (brokerConfig.getBrokerJavaOpts() != null) { - brokerPods.forEach(pod -> { - ExecutionResultData result = KubeCMDClient.runOnCluster("exec", pod.getMetadata().getName(), "-n", - pod.getMetadata().getNamespace(), "ps", "auxww"); - assertTrue(result.getRetCode(), result.getStdOut()); - assertTrue(result.getStdOut().contains(brokerConfig.getBrokerJavaOpts()), - "Unable to find expected java opts in process argument list: " + result.getStdOut()); - }); - } - - if (brokerConfig.getTemplateSpec() != null) { - assertTemplateSpec(broker, brokerConfig.getTemplateSpec()); - } - } - - protected void assertTemplateSpec(Pod pod, PodTemplateSpec templateSpec) { - if (templateSpec.getMetadata().getLabels() != null) { - for (Map.Entry labelPair : templateSpec.getMetadata().getLabels().entrySet()) { - assertEquals(labelPair.getValue(), pod.getMetadata().getLabels().get(labelPair.getKey()), "Labels do not match"); - } - } - - if (templateSpec.getSpec().getAffinity() != null) { - assertEquals(templateSpec.getSpec().getAffinity(), pod.getSpec().getAffinity(), "Affinity rules do not match"); - } - - if (templateSpec.getSpec().getPriorityClassName() != null) { - assertEquals(templateSpec.getSpec().getPriorityClassName(), pod.getSpec().getPriorityClassName(), "Priority class names do not match"); - } - - if (templateSpec.getSpec().getTolerations() != null) { - for (Toleration expected : templateSpec.getSpec().getTolerations()) { - boolean found = false; - for (Toleration actual : pod.getSpec().getTolerations()) { - if (actual.equals(expected)) { - found = true; - break; - } - } - assertTrue(found, "Did not find expected toleration " + expected); - } - } - - for (Container expectedContainer : templateSpec.getSpec().getContainers()) { - for (Container actualContainer : pod.getSpec().getContainers()) { - if (expectedContainer.getName().equals(actualContainer.getName())) { - assertEquals(expectedContainer.getResources(), actualContainer.getResources()); - } - } - } - } - - protected void assertAdminConsole(InfraConfiguration adminConfig) { - log.info("Checking admin console infra"); - List adminPods = TestUtils.listAdminConsolePods(kubernetes, exampleAddressSpace); - assertEquals(1, adminPods.size()); - - List adminResources = adminPods.stream().findFirst().get().getSpec().getContainers() - .stream().map(Container::getResources).collect(Collectors.toList()); - - for (ResourceRequirements requirements : adminResources) { - assertEquals(adminConfig.getMemory(), requirements.getLimits().get("memory").getAmount(), - "Admin console memory limit incorrect"); - assertEquals(adminConfig.getMemory(), requirements.getRequests().get("memory").getAmount(), - "Admin console memory requests incorrect"); - if (adminConfig.getCpu() != null) { - assertEquals(adminConfig.getCpu(), requirements.getLimits().get("cpu").getAmount(), - "Admin console cpu limit incorrect"); - assertEquals(adminConfig.getCpu(), requirements.getRequests().get("cpu").getAmount(), - "Admin console cpu requests incorrect"); - } - } - - if (adminConfig.getTemplateSpec() != null) { - assertTemplateSpec(adminPods.get(0), adminConfig.getTemplateSpec()); - } - } - - protected void waitUntilInfraReady(Supplier assertCall, TimeoutBudget timeout) throws InterruptedException { - log.info("Start waiting for infra ready"); - AssertionFailedError lastException = null; - while (!timeout.timeoutExpired()) { - try { - assertCall.get(); - log.info("assert infra ready succeed"); - return; - } catch (AssertionFailedError e) { - lastException = e; - } - log.debug("next iteration, remaining time: {}", timeout.timeLeft()); - Thread.sleep(5000); - } - log.error("Timeout assert infra expired"); - if (lastException != null) { - throw lastException; - } - } - - protected PersistentVolumeClaim getBrokerPVCData(Pod broker) { - String brokerVolumeClaimName = broker.getSpec().getVolumes().stream() - .filter(volume -> volume.getName().equals("data")) - .findFirst().get() - .getPersistentVolumeClaim().getClaimName(); - return TestUtils.listPersistentVolumeClaims(kubernetes, exampleAddressSpace).stream() - .filter(pvc -> pvc.getMetadata().getName().equals(brokerVolumeClaimName)) - .findFirst().get(); - } - - protected Boolean volumeResizingSupported() throws Exception { - List brokerPods = TestUtils.listBrokerPods(kubernetes, exampleAddressSpace); - assertEquals(1, brokerPods.size()); - Pod broker = brokerPods.stream().findFirst().get(); - PersistentVolumeClaim brokerVolumeClaim = getBrokerPVCData(broker); - String brokerStorageClassName = brokerVolumeClaim.getSpec().getStorageClassName(); - if (brokerStorageClassName != null) { - StorageClass brokerStorageClass = kubernetes.getStorageClass(brokerStorageClassName); - if (resizingStorageProvisioners.contains(brokerStorageClass.getProvisioner())) { - if (brokerStorageClass.getAllowVolumeExpansion() != null && brokerStorageClass.getAllowVolumeExpansion()) { - log.info("Testing broker volume resize because of {}:{}", brokerStorageClassName, brokerStorageClass.getProvisioner()); - return true; - } else { - log.info("Skipping broker volume resize due to allowVolumeExpansion in StorageClass {} disabled", brokerStorageClassName); - } - } else { - log.info("Skipping broker volume resize due to provisioner: {}", brokerStorageClass.getProvisioner()); - } - } else { - log.info("Skipping broker volume resize due to missing StorageClass name in PVC {}", brokerVolumeClaim.getMetadata().getName()); - } - return false; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java deleted file mode 100644 index 6e04ec1a432..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/mqtt/MqttPublishTestBase.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.mqtt; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.nio.charset.StandardCharsets; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.mqtt.MqttClientFactory; -import io.enmasse.systemtest.mqtt.MqttClientFactory.Builder; -import io.enmasse.systemtest.mqtt.MqttUtils; -import io.enmasse.systemtest.utils.AddressUtils; - -public abstract class MqttPublishTestBase extends TestBase implements ITestBaseShared { - - private static final String MYTOPIC = "mytopic"; - private static final Logger log = CustomLogger.getLogger(); - - public void testPublishQoS0() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(0); - }); - - this.publish(messages, 0); - } - - public void testPublishQoS1() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(1); - }); - - this.publish(messages, 1); - } - - public void testPublishQoS2() throws Exception { - List messages = Stream.generate(MqttMessage::new).limit(3).collect(Collectors.toList()); - messages.forEach(m -> { - m.setPayload(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8)); - m.setQos(2); - }); - - this.publish(messages, 2); - } - - public void testRetainedMessages() throws Exception { - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), "test-topic1")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic1") - .withPlan(topicPlan()) - .endSpec() - .build(); - resourcesManager.setAddresses(topic); - - MqttMessage retainedMessage = new MqttMessage(); - retainedMessage.setQos(1); - retainedMessage.setPayload("retained-message".getBytes(StandardCharsets.UTF_8)); - retainedMessage.setId(1); - retainedMessage.setRetained(true); - - // send retained message to the topic - Builder publisherBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials); - customizeClient(publisherBuilder); - try(IMqttClient publisher = publisherBuilder.create()) { - publisher.connect(); - publisher.publish(topic.getSpec().getAddress(), retainedMessage); - publisher.disconnect(); - } - - // each client which will subscribe to the topic should receive retained message! - Builder subscriberBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials); - customizeClient(subscriberBuilder); - try(IMqttClient subscriber = subscriberBuilder.create()) { - subscriber.connect(); - CompletableFuture messageFuture = new CompletableFuture<>(); - subscriber.subscribe(topic.getSpec().getAddress(), (topic1, message) -> messageFuture.complete(message)); - MqttMessage receivedMessage = messageFuture.get(1, TimeUnit.MINUTES); - assertTrue(receivedMessage.isRetained(), "Retained message expected"); - - subscriber.disconnect(); - } - } - - private void publish(List messages, int subscriberQos) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(getSharedAddressSpace().getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(getSharedAddressSpace(), MYTOPIC)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(MYTOPIC) - .withPlan(topicPlan()) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - Builder clientBuilder = new MqttClientFactory.Builder() - .usernameAndPassword(defaultCredentials) - .mqttConnectionOptions(options -> { - options.setConnectionTimeout(options.getConnectionTimeout() * 2); // Default is 30 seconds, increase it to 1 min. - options.setAutomaticReconnect(true); - }); - customizeClient(clientBuilder); - - try (IMqttClient client = clientBuilder.create()) { - log.info("Connecting"); - client.connect(); - - List> receiveFutures = MqttUtils.subscribeAndReceiveMessages(client, dest.getSpec().getAddress(), messages.size(), subscriberQos); - List> publishFutures = MqttUtils.publish(client, dest.getSpec().getAddress(), messages); - - int publishCount = MqttUtils.awaitAndReturnCode(publishFutures, 1, TimeUnit.MINUTES); - assertThat("Incorrect count of messages published", - publishCount, is(messages.size())); - - int receivedCount = MqttUtils.awaitAndReturnCode(receiveFutures, 2, TimeUnit.MINUTES); - assertThat("Incorrect count of messages received", - receivedCount, is(messages.size())); - } - - } - - protected void customizeClient(Builder mqttClientBuilder) { - //optional to implement - } - - protected String topicPlan() { - return getDefaultPlan(AddressType.TOPIC); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java deleted file mode 100644 index d77f1ae052a..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/olm/OLMTestBase.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.olm; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpConnectOptions; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestIsolatedStandard; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.cluster.CRCCluster; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.AuthServiceUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.vertx.core.json.JsonArray; -import io.vertx.core.json.JsonObject; -import io.vertx.proton.ProtonQoS; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public abstract class OLMTestBase extends TestBase implements ITestIsolatedStandard { - private static Logger log = CustomLogger.getLogger(); - - private static final int CR_TIMEOUT_MILLIS = 30000; - private List exampleResources = new ArrayList<>(); - - protected abstract String getInstallationNamespace(); - - protected abstract String getDifferentAddressSpaceNamespace(); - - @BeforeAll - void setupExampleResources() throws Exception { - ExecutionResultData result = KubeCMDClient.runOnCluster("get", "csv", "-n", getInstallationNamespace(), "-o", "json", "-l", "app=enmasse"); - JsonObject csvList = new JsonObject(result.getStdOut()); - JsonObject csv = csvList.getJsonArray("items").getJsonObject(0); - String almExamples = csv.getJsonObject("metadata").getJsonObject("annotations").getString("alm-examples"); - JsonArray examples = new JsonArray(almExamples); - exampleResources = examples.stream().map(o -> (JsonObject) o).collect(Collectors.toList()); - - Set infraKinds = Set.of("StandardInfraConfig", "BrokeredInfraConfig", "AddressPlan", "AddressSpacePlan", "AuthenticationService"); - - for (JsonObject example : exampleResources) { - LOGGER.info("Example: {}", example); - String kind = example.getString("kind"); - if (kind.equals("AuthenticationService") && kubernetes.getCluster() instanceof CRCCluster) { - log.info("Creating standard-authservice with no persistence because of CRC cluster"); - AuthenticationService authService = AuthServiceUtils.createStandardAuthServiceObject("standard-authservice", false); - authService.getMetadata().setNamespace(getInstallationNamespace()); - kubernetes.getAuthenticationServiceClient(getInstallationNamespace()).create(authService); - } else if (infraKinds.contains(kind)) { - log.info("Creating {}", example.toString()); - createCR(getInstallationNamespace(), example); - } - } - TestUtils.waitUntilDeployed(getInstallationNamespace()); - TestUtils.waitForPodReady("standard-authservice", getInstallationNamespace()); - TestUtils.waitForSchemaInSync("standard-small"); - var addressSpacePlanClient = kubernetes.getAddressSpacePlanClient(getInstallationNamespace()); - TestUtils.waitUntilCondition("AddressSpacePlan standard-small visible", - phase -> addressSpacePlanClient.withName("standard-small").get() != null, - new TimeoutBudget(2, TimeUnit.MINUTES)); - - } - - @AfterEach - void deleteAddressSpace(ExtensionContext context) throws Exception { - if (context.getExecutionException().isPresent()) { //test failed - Path path = TestUtils.getFailedTestLogsPath(context); - GlobalLogCollector collector = new GlobalLogCollector(Kubernetes.getInstance(), path, getInstallationNamespace()); - collector.collectLogsOfPodsInNamespace(getInstallationNamespace()); - collector.collectEvents(getInstallationNamespace()); - } - for (String namespace : Arrays.asList(getInstallationNamespace(), getDifferentAddressSpaceNamespace())) { - AddressSpace addressSpace = kubernetes.getAddressSpaceClient(namespace).withName("myspace").get(); - if (addressSpace != null) { - resourcesManager.deleteAddressSpace(addressSpace); - } - } - } - - @AfterAll - void teardownExampleResources() throws Exception { - if (!environment.skipCleanup()) { - for (JsonObject example : exampleResources) { - log.info("Deleting {}", example.toString()); - KubeCMDClient.deleteCR(getInstallationNamespace(), example.toString(), CR_TIMEOUT_MILLIS); - } - kubernetes.deleteNamespace(getDifferentAddressSpaceNamespace()); - } - } - - protected void doTestExampleResourcesSameNamespaceAsOperator() throws Exception { - createdUserResources(getInstallationNamespace()); - } - - protected void doTestExampleResourcesDifferentNamespaceThanOperator() throws Exception { - kubernetes.createNamespace(getDifferentAddressSpaceNamespace()); - createdUserResources(getDifferentAddressSpaceNamespace()); - } - - private void createdUserResources(String addressSpaceNamespace) throws Exception { - JsonObject exampleAddressSpace = exampleResources.stream() - .filter(example -> example.getString("kind").equals("AddressSpace")) - .findFirst() - .orElseThrow(() -> new IllegalStateException("Example resources don't contain an address space")); - log.info("Creating {}", exampleAddressSpace.getString("kind")); - createCR(addressSpaceNamespace, exampleAddressSpace); - var client = kubernetes.getAddressSpaceClient(addressSpaceNamespace); - TestUtils.waitUntilCondition("Address space visible", - phase -> client.withName("myspace").get() != null, new TimeoutBudget(30, TimeUnit.SECONDS)); - resourcesManager.waitForAddressSpaceReady(client.withName("myspace").get()); - - - for (JsonObject example : exampleResources) { - String kind = example.getString("kind"); - if (kind.equals("Address") || kind.equals("MessagingUser")) { - log.info("Creating {}", kind); - createCR(addressSpaceNamespace, example); - } - } - Thread.sleep(10_000); - TestUtils.waitUntilDeployed(getInstallationNamespace()); - var addressClient = kubernetes.getAddressClient(addressSpaceNamespace); - TestUtils.waitUntilCondition("Address visible", - phase -> addressClient.withName("myspace.myqueue").get() != null, - new TimeoutBudget(30, TimeUnit.SECONDS)); - AddressUtils.waitForDestinationsReady(addressClient.withName("myspace.myqueue").get()); - - // Test basic messages - AddressSpace exampleSpace = kubernetes.getAddressSpaceClient(addressSpaceNamespace).withName("myspace").get(); - Address exampleAddress = kubernetes.getAddressClient(addressSpaceNamespace).withName("myspace.myqueue").get(); - - AmqpClient amqpClient = resourcesManager.getAmqpClientFactory().createClient(new AmqpConnectOptions() - .setTerminusFactory(new QueueTerminusFactory()) - .setQos(ProtonQoS.AT_LEAST_ONCE) - .setCert(new String(Base64.getDecoder().decode(exampleSpace.getStatus().getCaCert()), StandardCharsets.UTF_8)) - .setEndpoint(kubernetes.getExternalEndpoint("messaging-" + AddressSpaceUtils.getAddressSpaceInfraUuid(exampleSpace), getInstallationNamespace())) - .setUsername("user") - .setPassword("enmasse")); - - int messageCount = 10; - Future sent = amqpClient.sendMessages(exampleAddress.getSpec().getAddress(), TestUtils.generateMessages(messageCount)); - assertEquals(messageCount, sent.get(1, TimeUnit.MINUTES).intValue(), "Incorrect count of messages send"); - - Future> received = amqpClient.recvMessages(exampleAddress.getSpec().getAddress(), messageCount); - assertEquals(messageCount, received.get(1, TimeUnit.MINUTES).size(), "Incorrect count of messages received"); - } - - private void createCR(String namespace, JsonObject cr) throws IOException { - ExecutionResultData res = KubeCMDClient.createCR(namespace, cr.toString(), CR_TIMEOUT_MILLIS); - if (!res.getRetCode()) { - Assertions.fail(res.getStdErr()); - } - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java deleted file mode 100644 index 318ab8ad12b..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/plans/PlansTestBase.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.bases.plans; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestBaseIsolated; -import io.enmasse.systemtest.broker.ArtemisUtils; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.transport.DeliveryState; -import org.apache.qpid.proton.message.Message; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; -import org.hamcrest.TypeSafeMatcher; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class PlansTestBase extends TestBase { - private static Logger log = CustomLogger.getLogger(); - - - public static Matcher
assertAddressStatusNotReady(final String messageContains) { - return PlansTestBase.assertAddressStatus(false, Optional.empty(), Optional.of(messageContains)); - } - - public static Matcher
assertAddressStatusReady(String actualPlan) { - return PlansTestBase.assertAddressStatus(true, Optional.of(actualPlan), Optional.empty()); - } - - public static Matcher
assertAddressStatus(final boolean ready, final Optional actualPlan, final Optional messageContains) { - return new TypeSafeMatcher<>() { - @Override - public void describeTo(Description description) { - description.appendText("should match ready ").appendValue(ready); - actualPlan.ifPresent(s -> description.appendText("should match plan ").appendValue(s)); - messageContains.ifPresent(s -> description.appendText("should status should contain ").appendValue(s)); - } - - @Override - protected void describeMismatchSafely(Address a, Description description) { - if (a.getStatus() == null) { - description.appendText("address.status is absent"); - } - if (ready != a.getStatus().isReady()) { - description.appendText("ready was ").appendValue(a.getStatus().isReady()); - } - if (actualPlan.isPresent()) { - if (a.getStatus().getPlanStatus() == null) { - description.appendText("address.status.planStatus is absent"); - } else if (!actualPlan.get().equals(a.getStatus().getPlanStatus().getName())) { - description.appendText("actual plan was ").appendValue(a.getStatus().getPlanStatus().getName()); - } - } - if (messageContains.isPresent()) { - String cc = String.join(":", a.getStatus().getMessages()); - description.appendText("messages were: ").appendValue(cc); - } - - } - - @Override - public boolean matchesSafely(Address a) { - if (a.getStatus() == null) { - return false; - } - if (ready != a.getStatus().isReady()) { - return false; - } - if (actualPlan.isPresent() && !actualPlan.get().equals(a.getStatus().getPlanStatus().getName())) { - return false; - } - if (messageContains.isPresent()) { - Optional match = a.getStatus().getMessages().stream().filter(m -> m.contains(messageContains.get())).findFirst(); - return match.isPresent(); - } else { - return true; - } - } - }; - } - - public void doTestUnknownAddressPlan(AddressSpace addressSpace, List stageHolders) throws Exception { - - resourcesManager.createAddressSpace(addressSpace); - - do { - log.info("Starting stage"); - - List stages = stageHolders.stream().filter(StageHolder::hasStage).map(StageHolder::popStage).collect(Collectors.toList()); - - if (stages.isEmpty()) { - break; - } - - stages.stream().map(StageHolder.Stage::getAddress).forEach(address -> { - Kubernetes.getInstance().getAddressClient(address.getMetadata().getNamespace()).createOrReplace(address); - }); - - stages.forEach(s -> { - AtomicReference lastMatch = new AtomicReference<>(); - - boolean rv = TestUtils.waitUntilCondition(() -> { - Address current = resourcesManager.getAddress(s.getAddress().getMetadata().getNamespace(), s.getAddress()); - Matcher
matcher = s.getMatcher(); - boolean matches = matcher.matches(current); - StringDescription desc = new StringDescription(); - matcher.describeMismatch(current, desc); - lastMatch.set(desc.toString()); - if (matches) { - log.info("Address {} is now in expected state: {}", current.getMetadata().getName(), current.getStatus()); - } else { - log.info("Address {} is not in expected state: {} {}", current.getMetadata().getName(), lastMatch, current.getStatus()); - } - return matches; - }, Duration.ofMinutes(2), Duration.ofSeconds(10)); - assertTrue(rv, String.format("address %s did not reach desired state : %s", s.getAddress().getMetadata().getName(), lastMatch)); - }); - } while(true); - } - - public void doTestUpdatePlanBrokerCreditChangesPerAddressMaxSize(AddressSpace addressSpace, Address queueDest, AddressPlan phase1, AddressPlan phase2, AddressPlan redefinedPhase2, AmqpClientFactory amqpClientFactory) throws Exception { - //get destination - Address queue = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(queueDest.getMetadata().getName()).get(); - - String assertMessage = "Queue plan wasn't set properly"; - assertEquals(queue.getSpec().getPlan(), - phase1.getMetadata().getName(), assertMessage); - - //Send messages to ensure queue fills up - UserCredentials user = new UserCredentials("test-newplan-name", "test_newplan_password"); - resourcesManager.createOrUpdateUser(addressSpace, user); - - AmqpClient client = amqpClientFactory.createQueueClient(addressSpace); - client.getConnectOptions().setCredentials(user); - byte[] bytes = new byte[1024 * 100]; - Random random = new Random(); - Message message = Message.Factory.create(); - random.nextBytes(bytes); - message.setBody(new AmqpValue(new Data(new Binary(bytes)))); - message.setAddress(queue.getSpec().getAddress()); - message.setDurable(true); - - Stream messageStream = Stream.generate(() -> message); - int messagesSent = client.sendMessagesCheckDelivery(queue.getSpec().getAddress(), messageStream::iterator, - protonDelivery -> protonDelivery.remotelySettled() && protonDelivery.getRemoteState().getType().equals(DeliveryState.DeliveryStateType.Rejected)) - .get(5, TimeUnit.MINUTES); - - assertTrue(messagesSent > 0, "Verify a few messages were sent before queue fills up"); - - //Verify maxSizeBytes are set - assertMaxSizeBytes(addressSpace, queue, 524288); - - //Redefine address to use next plan - Address largeQueue = new AddressBuilder(queue).editSpec().withPlan(phase2.getMetadata().getName()).endSpec().build(); - ITestBaseIsolated.isolatedResourcesManager.replaceAddress(largeQueue); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), largeQueue); - awaitPlanStatusResourceSync(addressSpace, largeQueue, phase2); - assertMaxSizeBytes(addressSpace, queue, 734003); - - //Redefine plan to to have more credit - ITestBaseIsolated.isolatedResourcesManager.replaceAddressPlan(redefinedPhase2); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), largeQueue); - awaitPlanStatusResourceSync(addressSpace, largeQueue, redefinedPhase2); - assertMaxSizeBytes(addressSpace, queue, 943718); - } - - public void awaitPlanStatusResourceSync(AddressSpace addressSpace, Address dest, AddressPlan plan) { - TestUtils.waitUntilCondition(() -> { - Address a = kubernetes.getAddressClient(addressSpace.getMetadata().getNamespace()).withName(dest.getMetadata().getName()).get(); - return a.getStatus().getPlanStatus() != null && a.getStatus().getPlanStatus().getResources().containsKey("broker") && - a.getStatus().getPlanStatus().getResources().get("broker").equals(plan.getResources().get("broker")); - }, Duration.ofMinutes(1), Duration.ofSeconds(1)); - } - - public void assertMaxSizeBytes(AddressSpace addressSpace, Address queue, Integer expected) throws Exception { - Map addressSettings = ArtemisUtils.getAddressSettings(kubernetes, addressSpace, queue.getSpec().getAddress()); - assertEquals(expected, (Integer) addressSettings.get("maxSizeBytes"), "maxSizeBytes should be set"); - } - - public class StageHolder { - private final AddressSpace addressSpace; - private final String addressName; - private final List stages = new ArrayList<>(); - - public class Stage { - private final String plan; - private final Matcher
matcher; - - Stage(Matcher
matcher, String plan) { - this.plan = plan; - this.matcher = matcher; - } - - public Address getAddress() { - return new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, addressName)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress(StageHolder.this.addressName) - .withPlan(this.plan) - .endSpec() - .build(); - } - - public Matcher
getMatcher() { - return matcher; - } - } - - public StageHolder(AddressSpace addressSpace, String addressName) { - this.addressSpace = addressSpace; - this.addressName = addressName; - } - - public StageHolder addStage(String plan, Matcher
addressMatcher) { - stages.add(new Stage(addressMatcher, plan)); - return this; - } - - public boolean hasStage() { - return !stages.isEmpty(); - } - - public Stage popStage() { - return stages.remove(0); - } - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java deleted file mode 100644 index 511e6506712..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/soak/SoakTestBase.java +++ /dev/null @@ -1,376 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.soak; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.systemtest.SysytemTestsErrorCollector; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.ThrowableRunner; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.shared.standard.QueueTest; -import io.enmasse.systemtest.shared.standard.TopicTest; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.TestUtils; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.slf4j.Logger; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static io.enmasse.systemtest.TestTag.SOAK; -import static org.hamcrest.CoreMatchers.is; - -@Tag(SOAK) -public abstract class SoakTestBase extends TestBase { - private static Logger log = CustomLogger.getLogger(); - private ArrayList clients = new ArrayList<>(); - private SysytemTestsErrorCollector collector = new SysytemTestsErrorCollector(); - - @BeforeEach - void setupMarathonTests() { - collector.clear(); - } - - //======================================================================================================== - // Runner tests methods - //======================================================================================================== - - protected void runTestInLoop(int durationMinutes, ThrowableRunner test) throws Exception { - log.info(String.format("Starting test running for %d minutes at %s", - durationMinutes, new Date().toString())); - int fails = 0; - int limit = 10; - int i = 0; - for (long stop = System.nanoTime() + TimeUnit.MINUTES.toNanos(durationMinutes); stop > System.nanoTime(); ) { - try { - log.info("*********************************** Test run {} ***********************************", ++i); - test.run(); - fails = 0; - } catch (Exception ex) { - log.warn("Test run {} failed with: {}", i, ex.getMessage()); - collector.addError(ex); - if (++fails >= limit) { - throw new IllegalStateException(String.format("Test failed: %d times in a row: %s", fails, collector.toString())); - } - } finally { - closeClients(); - log.info("***********************************************************************************"); - Thread.sleep(60_000); - } - } - if (!collector.verify()) { - throw new IllegalStateException(String.format("Test failed with these exceptions: %s", collector.toString())); - } - } - - private void closeClients() { - for (AmqpClient client : clients) { - try { - client.close(); - log.info("Client is closed."); - } catch (Exception ex) { - collector.addError(ex); - } - } - clients.clear(); - } - - //======================================================================================================== - // Tests methods - //======================================================================================================== - protected void doTestQueueSendReceiveLong(AddressSpace addressSpace) throws Exception { - resourcesManager.createAddressSpace(addressSpace); - - int msgCount = 1000; - int queueCount = 10; - int senderCount = 10; - int recvCount = 20; - - List
queueList = new ArrayList<>(); - - //create queues - for (int i = 0; i < queueCount; i++) { - queueList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-sendreceive-" + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-sendreceive-" + i) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - } - resourcesManager.setAddresses(queueList.toArray(new Address[0])); - - List msgBatch = TestUtils.generateMessages(msgCount); - - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(addressSpace, credentials); - - runTestInLoop(30, () -> { - //create client - AmqpClient client = resourcesManager.getAmqpClientFactory().createQueueClient(addressSpace); - client.getConnectOptions().setCredentials(credentials); - clients.add(client); - - //attach receivers - List>> recvResults = new ArrayList<>(); - for (int i = 0; i < recvCount / 2; i++) { - recvResults.add(client.recvMessages(queueList.get(i).getSpec().getAddress(), msgCount / 2)); - recvResults.add(client.recvMessages(queueList.get(i).getSpec().getAddress(), msgCount / 2)); - } - - //attach senders - for (int i = 0; i < senderCount; i++) { - collector.checkThat(client.sendMessages(queueList.get(i).getSpec().getAddress(), msgBatch).get(2, TimeUnit.MINUTES), is(msgBatch.size())); - } - - //check received messages - for (int i = 0; i < recvCount; i++) { - collector.checkThat(recvResults.get(i).get().size(), is(msgCount / 2)); - } - }); - } - - protected void doTestAuthSendReceiveLong(AddressSpace addressSpace) throws Exception { - log.info("testAuthSendReceiveLong start"); - resourcesManager.createAddressSpace(addressSpace); - log.info("Address space '{}'created", addressSpace); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-auth-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-auth-queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - Address topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-auth-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-auth-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - resourcesManager.setAddresses(queue, topic); - log.info("Addresses '{}', '{}' created", queue.getSpec().getAddress(), topic.getSpec().getAddress()); - - UserCredentials user = new UserCredentials("test-user", "test-user"); - resourcesManager.createOrUpdateUser(addressSpace, user); - - runTestInLoop(30, () -> { - log.info("Start test loop basic auth tests"); - getClientUtils().assertCanConnect(addressSpace, user, Arrays.asList(queue, topic), resourcesManager); - getClientUtils().assertCannotConnect(addressSpace, new UserCredentials("nobody", "nobody"), Arrays.asList(queue, topic), resourcesManager); - }); - log.info("testAuthSendReceiveLong finished"); - } - - protected void doTestTopicPubSubLong(AddressSpace addressSpace) throws Exception { - resourcesManager.createAddressSpace(addressSpace); - - int msgCount = 1000; - int topicCount = 10; - - List
topicList = new ArrayList<>(); - - //create queues - for (int i = 0; i < topicCount; i++) { - topicList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-topic-pubsub-" + i)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic-pubsub-" + i) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } - resourcesManager.setAddresses(topicList.toArray(new Address[0])); - - List msgBatch = TestUtils.generateMessages(msgCount); - - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(addressSpace, credentials); - runTestInLoop(30, () -> { - AmqpClient client = resourcesManager.getAmqpClientFactory().createTopicClient(addressSpace); - client.getConnectOptions().setCredentials(credentials); - clients.add(client); - - //attach subscibers - List>> recvResults = new ArrayList<>(); - for (int i = 0; i < topicCount; i++) { - recvResults.add(client.recvMessages(String.format("test-topic-pubsub-%d", i), msgCount)); - } - - //attach producers - for (int i = 0; i < topicCount; i++) { - collector.checkThat(client.sendMessages(topicList.get(i).getSpec().getAddress(), msgBatch).get(2, TimeUnit.MINUTES), is(msgBatch.size())); - } - - //check received messages - for (int i = 0; i < topicCount; i++) { - collector.checkThat(recvResults.get(i).get().size(), is(msgCount)); - } - }); - } - - //======================================================================================================== - // Help methods - //======================================================================================================== - - private void doAddressTest(AddressSpace addressSpace, String topicPattern, - String queuePattern, UserCredentials credentials) throws Exception { - List
queueList = new ArrayList<>(); - List
topicList = new ArrayList<>(); - - int destinationCount = 20; - - for (int i = 0; i < destinationCount; i++) { - queueList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, queuePattern + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-via-web") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - topicList.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, topicPattern + i)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(topicPattern + i) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } - - AmqpClient queueClient; - AmqpClient topicClient; - - resourcesManager.setAddresses(queueList.toArray(new Address[0])); - resourcesManager.appendAddresses(topicList.toArray(new Address[0])); - - queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(addressSpace); - queueClient.getConnectOptions().setCredentials(credentials); - clients.add(queueClient); - - topicClient = resourcesManager.getAmqpClientFactory().createTopicClient(addressSpace); - topicClient.getConnectOptions().setCredentials(credentials); - clients.add(topicClient); - - for (Address queue : queueList) { - QueueTest.runQueueTest(queueClient, queue, 1024); - } - - for (Address topic : topicList) { - TopicTest.runTopicTest(topicClient, topic, 1024); - } - - resourcesManager.deleteAddresses(queueList.toArray(new Address[0])); - resourcesManager.deleteAddresses(topicList.toArray(new Address[0])); - Thread.sleep(15000); - } - - protected void doTestLoad(AddressSpaceType type, String addressSpacePlans, String addressPlan) throws Exception { - - runTestInLoop(120, () -> { - int count = 5; - AmqpClient queueClient; - Map pairs = new HashMap(); - - - List addressSpaceList = IntStream.range(0, count).mapToObj(i -> - new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-address-space-" + i) - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(type.toString()) - .withPlan(addressSpacePlans) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build()).collect(Collectors.toList()); - - resourcesManager.createAddressSpace(addressSpaceList.toArray(new AddressSpace[0])); - List
addresses = new LinkedList<>(); - for (AddressSpace space : addressSpaceList) { - UserCredentials credentials = new UserCredentials("test", "test"); - resourcesManager.createOrUpdateUser(space, credentials); - queueClient = resourcesManager.getAmqpClientFactory().createQueueClient(space); - queueClient.getConnectOptions().setCredentials(credentials); - clients.add(queueClient); - - for (int i = 0; i < count; i++) { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(space.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(space, "test-address-" + i)) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-address-" + i) - .withPlan(addressPlan) - .endSpec() - .build()); - pairs.put(addresses.get(i), queueClient); - } - } - resourcesManager.setAddresses(addresses.toArray(new Address[0])); - for (Map.Entry pair : pairs.entrySet()) { - QueueTest.runQueueTest(pair.getValue(), pair.getKey(), 1024); - } - - for (AddressSpace space : addressSpaceList) { - resourcesManager.deleteAddressSpace(space); - } - }); - } -} - - - - - - - diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java deleted file mode 100644 index 47cc690d419..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/ConsoleTest.java +++ /dev/null @@ -1,2074 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.web; - - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.address.model.AuthenticationServiceType; -import io.enmasse.address.model.CertSpecBuilder; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AuthenticationService; -import io.enmasse.admin.model.v1.ResourceAllowance; -import io.enmasse.admin.model.v1.ResourceRequest; -import io.enmasse.config.LabelKeys; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.certs.CertBundle; -import io.enmasse.systemtest.certs.CertProvider; -import io.enmasse.systemtest.certs.openssl.CertPair; -import io.enmasse.systemtest.certs.openssl.CertSigningRequest; -import io.enmasse.systemtest.certs.openssl.OpenSSLUtil; -import io.enmasse.systemtest.clients.ClientUtils; -import io.enmasse.systemtest.clients.ClientUtils.ClientAttacher; -import io.enmasse.systemtest.executor.Exec; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.info.TestInfo; -import io.enmasse.systemtest.isolated.Credentials; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.logs.GlobalLogCollector; -import io.enmasse.systemtest.messagingclients.ExternalMessagingClient; -import io.enmasse.systemtest.messagingclients.rhea.RheaClientReceiver; -import io.enmasse.systemtest.messagingclients.rhea.RheaClientSender; -import io.enmasse.systemtest.model.address.AddressStatus; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.selenium.SeleniumProvider; -import io.enmasse.systemtest.selenium.page.ConsoleWebPage; -import io.enmasse.systemtest.selenium.resources.AddressWebItem; -import io.enmasse.systemtest.selenium.resources.ConnectionWebItem; -import io.enmasse.systemtest.selenium.resources.FilterType; -import io.enmasse.systemtest.selenium.resources.SortType; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.AuthServiceUtils; -import io.enmasse.systemtest.utils.Count; -import io.enmasse.systemtest.utils.PlanUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.ConfigMap; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.api.model.apps.Deployment; -import io.fabric8.openshift.api.model.Route; -import org.apache.qpid.proton.message.Message; -import org.eclipse.hono.util.Strings; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.function.Predicate; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.either; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -public abstract class ConsoleTest extends TestBase { - private static Logger log = CustomLogger.getLogger(); - SeleniumProvider selenium = SeleniumProvider.getInstance(); - private List clientsList; - private ConsoleWebPage consolePage; - - @AfterEach - public void tearDownWebConsoleTests(ExtensionContext context) throws Exception { - if (clientsList != null) { - getClientUtils().stopClients(clientsList, context); - clientsList.clear(); - } - } - - //============================================================================================ - //============================ do test methods for addressspace part========================== - //============================================================================================ - - protected void doTestOpen() throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.getAddressSpaceItems(); - consolePage.logout(); - } - - protected void doTestCreateDeleteAddressSpace(AddressSpace addressSpace) throws Exception { - resourcesManager.addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - consolePage.deleteAddressSpace(addressSpace); - } - - protected void doTestGoneAwayPageAfterAddressSpaceDeletion() throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(AddressSpaceType.STANDARD); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - consolePage.openAddressList(addressSpace); - resourcesManager.deleteAddressSpaceWithoutWait(addressSpace); - try { - consolePage.awaitGoneAwayPage(); - } finally { - resourcesManager.deleteAddressSpace(addressSpace); - } - } - - protected void doTestGoneAwayPageAfterAddressDeletion() throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(AddressSpaceType.STANDARD); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - consolePage.openAddressList(addressSpace); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - consolePage.createAddress(address); - consolePage.openClientsList(address); - resourcesManager.deleteAddresses(address); - consolePage.awaitGoneAwayPage(); - resourcesManager.deleteAddressSpace(addressSpace); - } - - protected void doTestSnippetClient(AddressSpaceType addressSpaceType) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - String firstLine = getSnippetFirstLine(addressSpace); - assertTrue(firstLine.startsWith(KubeCMDClient.getCMD()), "Snippet has right type of cmd client."); - } - - protected void doTestAddressSpaceSnippet(AddressSpaceType addressSpaceType) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - - getAndExecAddressSpaceDeploymentSnippet(addressSpace); - assertTrue(AddressSpaceUtils.addressSpaceExists(Kubernetes.getInstance().getInfraNamespace(), - addressSpace.getMetadata().getName())); - resourcesManager.waitForAddressSpaceReady(addressSpace); - resourcesManager.deleteAddressSpace(addressSpace); - } - - - protected void doTestCreateAddrSpaceWithCustomAuthService() throws Exception { - AuthenticationService standardAuth = AuthServiceUtils.createStandardAuthServiceObject("test-standard-authservice", true); - resourcesManager.createAuthService(standardAuth); - - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-custom-auth") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName(standardAuth.getMetadata().getName()) - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.addToAddressSpaces(addressSpace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - } - - protected void doTestViewAddressSpace() throws Exception { - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-view-console") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.createAddressSpace(addressSpace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - waitUntilAddressSpaceActive(addressSpace); - consolePage.deleteAddressSpace(addressSpace); - } - - protected void doTestCreateAddrSpaceNonClusterAdminMinimal() throws Exception { - int addressCount = 4; - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - KubeCMDClient.createNamespace(namespace); - kubernetes.getClient().rbac().clusterRoles().createOrReplaceWithNew() - .editOrNewMetadata() - .withName(namespace) - .endMetadata() - .addNewRule() - .withApiGroups("") - .withResources("namespaces") - .withVerbs("get") - .withResourceNames(namespace) - .endRule() - .done(); - - kubernetes.getClient().rbac().clusterRoleBindings().createOrReplaceWithNew() - .editOrNewMetadata() - .withName(namespace) - .endMetadata() - .addNewSubject() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("User") - .withName(user.getUsername()) - .endSubject() - .editOrNewRoleRef() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("ClusterRole") - .withName(namespace) - .endRoleRef() - .done(); - - kubernetes.getClient().rbac().roleBindings().inNamespace(namespace).createOrReplaceWithNew() - .editOrNewMetadata() - .withName("pepa-admin") - .withNamespace(namespace) - .endMetadata() - .addNewSubject() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("User") - .withName(user.getUsername()) - .endSubject() - .editOrNewRoleRef() - .withApiGroup("rbac.authorization.k8s.io") - .withKind("ClusterRole") - .withName("enmasse.io:tenant-edit") - .endRoleRef() - .done(); - - UserCredentials messagingUser = new UserCredentials("pepa", "zdepa"); - boolean success = false; - AddressSpace addressSpace = null; - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - - addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(namespace) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - - resourcesManager.createOrUpdateUser(addressSpace, messagingUser); - - consolePage.openAddressList(addressSpace); - - List
addresses = generateQueueTopicList(addressSpace, "test", IntStream.range(0, addressCount)); - consolePage.createAddresses(addresses.toArray(new Address[0])); - AddressUtils.waitForDestinationsReady(addresses.toArray(new Address[0])); - - clientsList = attachClients(addressSpace, addresses, messagingUser); - - consolePage.switchToConnectionTab(); - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(c -> c.getReceivers() > 0), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.switchToAddressTab(); - consolePage.openClientsList(addresses.get(1)); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getClientItems().stream() - .noneMatch(c -> Strings.isNullOrEmpty(c.getContainerId())), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for clients count"); - - consolePage.openConsolePage(); - success = true; - } finally { - try { - if (!success) { - GlobalLogCollector testDirLogCollector = new GlobalLogCollector(kubernetes, TestUtils.getFailedTestLogsPath(TestInfo.getInstance().getActualTest()), environment.namespace(), false); - testDirLogCollector.collectLogsOfPodsByLabels(environment.namespace(), null, - Collections.singletonMap(LabelKeys.INFRA_UUID, AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace))); - } - consolePage.deleteAddressSpace(addressSpace); - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - kubernetes.getClient().rbac().clusterRoleBindings().withName(namespace).delete(); - kubernetes.getClient().rbac().clusterRoles().withName(namespace).delete(); - } - } - } - - protected void doTestCreateAddrSpaceNonClusterAdmin() throws Exception { - int addressCount = 4; - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - UserCredentials messagingUser = new UserCredentials("pepa", "zdepa"); - KubeCMDClient.runOnCluster("create", "rolebinding", "clients-admin", "--clusterrole", "admin", "--user", user.getUsername(), "--namespace", SystemtestsKubernetesApps.MESSAGING_PROJECT); - boolean success = false; - AddressSpace addressSpace = null; - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - KubeCMDClient.createNamespace(namespace); - - addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(namespace) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - - resourcesManager.createOrUpdateUser(addressSpace, messagingUser); - - consolePage.openAddressList(addressSpace); - - List
addresses = generateQueueTopicList(addressSpace, "test", IntStream.range(0, addressCount)); - consolePage.createAddresses(addresses.toArray(new Address[0])); - AddressUtils.waitForDestinationsReady(addresses.toArray(new Address[0])); - - clientsList = attachClients(addressSpace, addresses, messagingUser); - - consolePage.switchToConnectionTab(); - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(c -> c.getReceivers() > 0), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.switchToAddressTab(); - consolePage.openClientsList(addresses.get(1)); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getClientItems().stream() - .noneMatch(c -> Strings.isNullOrEmpty(c.getContainerId())), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for clients count"); - - consolePage.openConsolePage(); - success = true; - } finally { - try { - if (!success) { - GlobalLogCollector testDirLogCollector = new GlobalLogCollector(kubernetes, TestUtils.getFailedTestLogsPath(TestInfo.getInstance().getActualTest()), environment.namespace(), false); - testDirLogCollector.collectLogsOfPodsByLabels(environment.namespace(), null, - Collections.singletonMap(LabelKeys.INFRA_UUID, AddressSpaceUtils.getAddressSpaceInfraUuid(addressSpace))); - } - consolePage.deleteAddressSpace(addressSpace); - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - } - } - } - - protected void doTestRestrictAddressSpaceView() throws Exception { - String namespace = "test-namespace"; - UserCredentials user = Credentials.userCredentials(); - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api-2") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.createAddressSpace(addressSpace); - try { - KubeCMDClient.loginUser(user.getUsername(), user.getPassword()); - KubeCMDClient.createNamespace(namespace); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), user); - consolePage.openConsolePage(); - assertNull(consolePage.getAddressSpaceItem(addressSpace)); - - } finally { - KubeCMDClient.loginUser(environment.getApiToken()); - KubeCMDClient.switchProject(environment.namespace()); - kubernetes.deleteNamespace(namespace); - } - } - - protected void doEditAddressSpace() throws Exception { - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - assertEquals(AddressSpacePlans.STANDARD_MEDIUM, - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - String currentConfig = resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan(); - consolePage.changeAddressSpacePlan(addressSpace, AddressSpacePlans.STANDARD_UNLIMITED); - AddressSpaceUtils.waitForAddressSpaceConfigurationApplied(addressSpace, currentConfig); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - assertEquals(AddressSpacePlans.STANDARD_UNLIMITED, - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - - consolePage.changeAuthService(addressSpace, "none-authservice", AuthenticationServiceType.NONE); - AddressSpaceUtils.waitForAddressSpaceReady(addressSpace); - assertEquals("none-authservice", - resourcesManager.getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getAuthenticationService().getName()); - } - - protected void doTestViewCustomPlans() throws Exception { - final String queuePlanName1 = "web-custom-plan-queue-1"; - final String queuePlanName2 = "web-custom-plan-queue-2"; - final String addressSpacePlanName = "web-addressspace-plan"; - //Custom address plans - AddressPlan testQueuePlan1 = PlanUtils.createAddressPlanObject(queuePlanName1, - AddressType.QUEUE, - Arrays.asList( - new ResourceRequest("broker", 0.001), - new ResourceRequest("router", 0.0002))); - AddressPlan testQueuePlan2 = PlanUtils.createAddressPlanObject(queuePlanName2, - AddressType.QUEUE, - Arrays.asList( - new ResourceRequest("broker", 0.01), - new ResourceRequest("router", 0.002))); - - getResourceManager().createAddressPlan(testQueuePlan1); - getResourceManager().createAddressPlan(testQueuePlan2); - - //Custom addressspace plan - List resources = Arrays.asList( - new ResourceAllowance("broker", 10_000), - new ResourceAllowance("router", 10_000), - new ResourceAllowance("aggregate", 10_000)); - List addressPlans = Arrays.asList(testQueuePlan1, testQueuePlan2); - - AddressSpacePlan addressSpacePlan = PlanUtils.createAddressSpacePlanObject(addressSpacePlanName, "default", AddressSpaceType.STANDARD, resources, addressPlans); - getResourceManager().createAddressSpacePlan(addressSpacePlan); - - AddressSpace addressSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-addr-space-api") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(addressSpacePlanName) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType(AddressType.QUEUE.toString()) - .withAddress("test-queue") - .withPlan(queuePlanName1) - .endSpec() - .build(); - - getResourceManager().addToAddressSpaces(addressSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addressSpace); - waitUntilAddressSpaceActive(addressSpace); - assertEquals(addressSpacePlanName, - getResourceManager().getAddressSpace(addressSpace.getMetadata().getName()).getSpec().getPlan()); - - consolePage.openAddressList(addressSpace); - consolePage.createAddress(queue); - - AddressWebItem addressWebItem = consolePage.getAddressItem(queue); - selenium.clickOnItem(addressWebItem.getActionDropDown()); - selenium.clickOnItem(addressWebItem.getEditMenuItem()); - selenium.clickOnItem(selenium.getWebElement(consolePage::getEditAddrPlan), "Edit address plan"); - assertTrue(selenium.getDriver().findElement(By.xpath("//option[@value='" + queuePlanName1 + "']")).getText().contains(queuePlanName1)); - } - - protected void doTestFilterAddrSpace() throws Exception { - int addressSpaceCount = 2; - AddressSpace brokered = new AddressSpaceBuilder() - .withNewMetadata() - .withName("brokered-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace standard = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.createAddressSpace(brokered, standard); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount)); - - consolePage.addFilter(FilterType.NAMESPACE, "blah"); - assertThat("Console should show empty list", consolePage.getAddressSpaceItems().size(), is(0)); - - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.TYPE, AddressSpaceType.BROKERED.toString()); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.addFilter(FilterType.TYPE, AddressSpaceType.STANDARD.toString()); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.NAME, "brokered"); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount / 2)); - - consolePage.addFilter(FilterType.NAME, "standard"); - assertThat("Console should show not empty list", consolePage.getAddressSpaceItems().size(), is(addressSpaceCount)); - - consolePage.deleteSelectedAddressSpaces(brokered, standard); - assertThat("Console should show empty list", consolePage.getAddressSpaceItems().size(), is(0)); - - WebElement emptyAddessSpace = selenium.getWebElement(() -> consolePage.getEmptyAddSpace()); - assertTrue(emptyAddessSpace.isDisplayed()); - } - - protected void doTestHelpLink() throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - String expectedUrl = environment.enmasseDocs(); - String actualLink = consolePage.getHelpLink(); - - assertEquals(expectedUrl, actualLink); - - if (expectedUrl.contains("enmasse.io")) { - consolePage.openHelpLink(expectedUrl); - } - - } - - protected void doTestFilterAddressSpaceStatus() throws Exception { - AddressSpace standard1 = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-1-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan(AddressSpacePlans.BROKERED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace standard2 = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-2-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - AddressSpace failed = new AddressSpaceBuilder() - .withNewMetadata() - .withName("failed-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.BROKERED.toString()) - .withPlan("unknown") - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - - resourcesManager.createAddressSpace(standard1, false); - resourcesManager.createAddressSpace(standard2, false); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard1)); - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard2)); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - - consolePage.addFilter(FilterType.STATUS, "Configuring"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - resourcesManager.waitForAddressSpaceReady(standard1); - resourcesManager.waitForAddressSpaceReady(standard2); - - consolePage.removeAllFilters(); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard1)); - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(standard2)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - resourcesManager.createAddressSpace(failed, false); - - consolePage.removeAllFilters(); - - selenium.waitUntilItemPresent(30, () -> consolePage.getAddressSpaceItem(failed)); - - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - - consolePage.addFilter(FilterType.STATUS, "Pending"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(1)); - - consolePage.addFilter(FilterType.STATUS, "Terminating"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - consolePage.removeAllFilters(); - - consolePage.addFilter(FilterType.NAME, "standard"); - consolePage.addFilter(FilterType.NAMESPACE, kubernetes.getInfraNamespace()); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - consolePage.addFilter(FilterType.STATUS, "Active"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(2)); - consolePage.addFilter(FilterType.TYPE, "Standard"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(1)); - consolePage.addFilter(FilterType.STATUS, "Pending"); - assertThat("Console does not show all addressspaces", consolePage.getAddressSpaceItems().size(), is(0)); - } - - protected void doTestListEndpoints() throws Exception { - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-1-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging-wss").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging-wss")).getHost()); - } - - protected void doTestEndpointSystemProvided() throws Exception { - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-2-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints(AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.selfsigned.name()) - .build(), null, "amqps")) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - protected void doTestEndpointOpenshiftProvided() throws Exception { - UserCredentials user = new UserCredentials("pepa", "kornys"); - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-3-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints( - AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.openshift.name()) - .build(), null, "amqps"), - AddressSpaceUtils.createEndpoint("messaging-wss", new CertSpecBuilder() - .withProvider(CertProvider.openshift.name()) - .build(), null, "https")) - .endSpec() - .build(); - - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addrSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addrSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType(AddressType.QUEUE.toString()) - .withAddress("test-queue") - .withPlan(DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - - resourcesManager.createOrUpdateUser(addrSpace, user); - - consolePage.openAddressList(addrSpace); - consolePage.createAddress(queue); - - consolePage.switchToEndpointTab(); - consolePage.getEndpointItems(); - - getClientUtils().assertCanConnect(addrSpace, user, Collections.singletonList(queue), resourcesManager); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging-wss").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging-wss")).getHost()); - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - protected void doTestEndpointCustomCertsProvided() throws Exception { - CertBundle bundle = OpenSSLUtil.createCertBundle("kornys"); - - AddressSpace addrSpace = new AddressSpaceBuilder() - .withNewMetadata() - .withName("standard-4-test-addr-space") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_SMALL) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .withEndpoints( - AddressSpaceUtils.createEndpoint("messaging", new CertSpecBuilder() - .withProvider(CertProvider.certBundle.name()) - .withTlsCert(bundle.getCertB64()) - .withTlsKey(bundle.getKeyB64()) - .build(), null, "amqps")) - .endSpec() - .build(); - - resourcesManager.addToAddressSpaces(addrSpace); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.createAddressSpace(addrSpace); - consolePage.openEndpointList(addrSpace); - consolePage.getEndpointItems(); - - assertEquals(consolePage.getEndpointItem(addrSpace.getMetadata().getName() + "." + "messaging").getHost(), - Objects.requireNonNull(AddressSpaceUtils.getEndpointByName(addrSpace, "messaging")).getHost()); - } - - //============================================================================================ - //============================ do test methods for address part ============================== - //============================================================================================ - - protected void doTestAddressSnippet(AddressSpaceType addressSpaceType, String destinationPlan) throws Exception { - AddressSpace addressSpace = generateAddressSpaceObject(addressSpaceType); - resourcesManager.createAddressSpace(addressSpace); - - Address address = generateAddressObject(addressSpace, destinationPlan); - getAndExecAddressDeploymentSnippet(addressSpace, address); - AddressUtils.waitForDestinationsReady(address); - AddressUtils.isAddressReady(addressSpace, address); - resourcesManager.deleteAddresses(address); - resourcesManager.deleteAddressSpace(addressSpace); - } - - protected void doTestCreateDeleteAddress(AddressSpace addressSpace, Address... destinations) throws Exception { - Kubernetes.getInstance().getAddressClient().inNamespace(addressSpace.getMetadata(). - getNamespace()).list().getItems().forEach(address -> log.info("Add from list: " + address)); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - for (Address dest : destinations) { - consolePage.createAddress(dest); - } - for (Address dest : destinations) { - consolePage.deleteAddress(dest); - } - } - - protected void doTestAddressStatus(AddressSpace addressSpace, Address destination) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(destination, false); - Thread.sleep(5000); - assertThat("Console failed, expected PENDING or READY state", - consolePage.getAddressItem(destination).getStatus(), - either(is(AddressStatus.PENDING)).or(is(AddressStatus.READY))); - - AddressUtils.waitForDestinationsReady(new TimeoutBudget(5, TimeUnit.MINUTES), destination); - Thread.sleep(5000); - assertEquals(AddressStatus.READY, consolePage.getAddressItem(destination).getStatus(), - "Console failed, expected READY state"); - } - - protected void doTestFilterAddressesByType(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddressesAndWait(addresses.toArray(new Address[0])); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - - consolePage.addFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - List items = consolePage.getAddressItems(); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount / 2), - items.size(), is(addressCount / 2)); //assert correct count - assertAddressType("Console failed, does not contains only address type queue", - items, AddressType.QUEUE); //assert correct type - - consolePage.removeAddressFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - - consolePage.addFilter(FilterType.TYPE, AddressType.TOPIC.toString()); - items = consolePage.getAddressItems(); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount / 2), - items.size(), is(addressCount / 2)); //assert correct count - assertAddressType("Console failed, does not contains only address type topic", - items, AddressType.TOPIC); //assert correct type - - consolePage.removeAddressFilter(FilterType.TYPE, AddressType.TOPIC.toString()); - assertThat(String.format("Console failed, does not contain %d addresses", addressCount), - consolePage.getAddressItems().size(), is(addressCount)); - } - - protected void doTestFilterAddressesByName(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddressesAndWait(addresses.toArray(new Address[0])); - - String subText = "queue"; - consolePage.addFilter(FilterType.NAME, subText); - List items = consolePage.getAddressItems(); - assertEquals(addressCount / 2, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount / 2)); - assertAddressName("Console failed, does not contain addresses contain " + subText, items, subText); - - subText = "topic"; - consolePage.addFilter(FilterType.NAME, subText); - items = consolePage.getAddressItems(); - assertEquals(addressCount, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount)); - - - consolePage.removeAddressFilter(FilterType.NAME, "queue"); - items = consolePage.getAddressItems(); - assertEquals(addressCount / 2, items.size(), - String.format("Console failed, does not contain %d addresses", addressCount / 2)); - assertAddressName("Console failed, does not contain addresses contain " + subText, items, subText); - - consolePage.removeAllFilters(); - assertEquals(addressCount, consolePage.getAddressItems().size(), - String.format("Console failed, does not contain %d addresses", addressCount)); - - consolePage.deleteSelectedAddresses(addresses.toArray(new Address[0])); - assertEquals(0, consolePage.getAddressItems().size(), - String.format("Console failed, does not contain %d addresses", 0)); - } - - - protected void doTestFilterAddressesByStatus(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - String nonexistentPlan = "foo-plan"; - IntStream.range(0, addressCount / 2) - .forEach(i -> { - addresses.get(i).getSpec().setPlan(nonexistentPlan); - ; - }); - List
goodAddresses = addresses.stream() - .filter(a -> !a.getSpec().getPlan().equals(nonexistentPlan)) - .collect(Collectors.toList()); - List
badAddresses = addresses.stream() - .filter(a -> a.getSpec().getPlan().equals(nonexistentPlan)) - .collect(Collectors.toList()); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - getResourceManager().appendAddresses(true, goodAddresses.toArray(new Address[0])); - getResourceManager().appendAddresses(false, badAddresses.toArray(new Address[0])); - - TestUtils.waitUntilCondition(() -> consolePage.getAddressItems().size() == addressCount, Duration.ofSeconds(30), Duration.ofMillis(500)); - - consolePage.addFilter(FilterType.STATUS, "Pending"); - List items = consolePage.getAddressItems(); - assertEquals(badAddresses.size(), items.size(), - String.format("Console failed, does not contain %d addresses when %s filter", badAddresses.size(), "Pending")); - - consolePage.addFilter(FilterType.STATUS, "Active"); - items = consolePage.getAddressItems(); - assertEquals(goodAddresses.size(), items.size(), - String.format("Console failed, does not contain %d addresses when %s filter", goodAddresses.size(), "Active")); - } - - protected void doTestPurgeMessages(AddressSpace addressSpace) throws Exception { - Address queue1 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue1")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue1") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - Address queue2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue2")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue2") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - Address queue3 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue3")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue3") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_XLARGE_QUEUE) - .endSpec() - .build(); - - resourcesManager.setAddresses(queue1, queue2, queue3); - - ExternalMessagingClient client = new ExternalMessagingClient() - .withClientEngine(new RheaClientSender()) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(addressSpace)) - .withCredentials(defaultCredentials) - .withCount(1000) - .withMessageBody("msg no. %d") - .withTimeout(30); - - assertTrue(client.withAddress(queue1).run(false)); - assertTrue(client.withAddress(queue2).run(false)); - assertTrue(client.withAddress(queue3).run(false)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - assertThat(String.format("Console failed, does not contain %d addresses", 3), - consolePage.getAddressItems().size(), is(3)); - - consolePage.purgeSelectedAddresses(queue1, queue3); - - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getAddressItem(queue1).getMessagesStored()); - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getAddressItem(queue3).getMessagesStored()); - - assertTrue(client.withAddress(queue2).withClientEngine(new RheaClientReceiver()).run(false)); - assertThat(client.getMessages().size(), is(1000)); - assertTrue(client.withAddress(queue3).withTimeout(10).withClientEngine(new RheaClientReceiver()).run(false)); - assertThat(client.getMessages().size(), is(0)); - } - - protected void doTestConnectionClose(AddressSpace addressSpace) throws Exception { - Address queue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue1") - .withPlan(addressSpace.getSpec().getType().equals(AddressSpaceType.BROKERED.toString()) ? DestinationPlan.BROKERED_QUEUE : DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - - resourcesManager.setAddresses(queue); - - ExternalMessagingClient client = new ExternalMessagingClient() - .withClientEngine(new RheaClientReceiver()) - .withMessagingRoute(AddressSpaceUtils.getMessagingRoute(addressSpace)) - .withCredentials(defaultCredentials) - .withCount(1) - .withReconnect(false) - .withTimeout(180); - - client.withAddress(queue).runAsync(false); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - selenium.waitUntilPropertyPresent(60, 1, () -> consolePage.getConnectionItems().size()); - - Optional connRow = consolePage.getConnectionItems().stream().findFirst(); - assertThat("Connection item not found", connRow.isPresent(), is(true)); - - consolePage.closeSelectedConnection(connRow.get()); - - selenium.waitUntilPropertyPresent(60, 0, () -> consolePage.getConnectionItems().size()); - } - - protected void doTestEditAddress(AddressSpace addressSpace, Address address, String plan) throws Exception { - resourcesManager.setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.changeAddressPlan(address, plan); - Thread.sleep(10_000); - AddressUtils.waitForDestinationsReady(address); - assertThat(resourcesManager.getAddress(kubernetes.getInfraNamespace(), address).getSpec().getPlan(), is(plan)); - } - - protected void doTestDeleteFilteredAddress(AddressSpace addressSpace) throws Exception { - int addressTotal = 2; - - Address destQueue = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address destTopic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-topic")) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("test-topic") - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddresses(destQueue, destTopic); - - consolePage.addFilter(FilterType.TYPE, AddressType.QUEUE.toString()); - List items = consolePage.getAddressItems(); - - assertEquals(addressTotal / 2, items.size(), - String.format("Console failed, filter does not contain %d addresses", addressTotal / 2)); - - assertAddressName("Console failed, filter does not contain addresses", items, "queue"); - - consolePage.deleteAddress(destQueue); - items = consolePage.getAddressItems(); - assertEquals(0, items.size()); - log.info("filtered address has been deleted and no longer present in filter"); - - consolePage.removeAllFilters(); - items = consolePage.getAddressItems(); - assertEquals(addressTotal / 2, items.size()); - } - - protected void doTestSortAddressesByName(AddressSpace addressSpace) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddresses(addresses.toArray(new Address[0])); - consolePage.sortAddresses(SortType.NAME, true); - assertSorted("Console failed, items are not sorted by name asc", consolePage.getAddressItems()); - consolePage.sortAddresses(SortType.NAME, false); - assertSorted("Console failed, items are not sorted by name desc", consolePage.getAddressItems(), true); - } - - protected void doTestSortAddressesBySenders(AddressSpace addressSpace) throws Exception { - doTestSortAddresses(addressSpace, - SortType.SENDERS, - this::attachClients, - a -> a.getSendersCount() > 0, - Comparator.comparingInt(AddressWebItem::getSendersCount)); - } - - protected void doTestSortAddressesByReceivers(AddressSpace addressSpace) throws Exception { - doTestSortAddresses(addressSpace, - SortType.RECEIVERS, - this::attachClients, - a -> a.getReceiversCount() > 0, - Comparator.comparingInt(AddressWebItem::getReceiversCount)); - } - - private void doTestSortAddresses(AddressSpace addressSpace, SortType sortType, ClientAttacher attacher, Predicate readyCondition, Comparator sortingComparator) throws Exception { - int addressCount = 4; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - getResourceManager().setAddresses(addresses.toArray(new Address[0])); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(addressCount, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - clientsList = attacher.attach(addressSpace, addresses, defaultCredentials); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItems().stream() - .allMatch(readyCondition), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for addresses count"); - - consolePage.sortAddresses(sortType, true); - assertSorted("Console failed, items are not sorted by count of senders asc", - consolePage.getAddressItems(), - sortingComparator); - - consolePage.sortAddresses(sortType, false); - assertSorted("Console failed, items are not sorted by count of senders desc", - consolePage.getAddressItems(), - true, - sortingComparator); - } - - protected void doTestSortConnectionsBySenders(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, - SortType.SENDERS, - this::attachClients, - c -> c.getSenders() > 0, - Comparator.comparingInt(ConnectionWebItem::getSenders)); - } - - protected void doTestSortConnectionsByReceivers(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, - SortType.RECEIVERS, - this::attachClients, - c -> c.getReceivers() > 0, - Comparator.comparingInt(ConnectionWebItem::getReceivers)); - } - - protected void doTestAddressLinks(AddressSpace addressSpace, String destinationPlan) throws Exception { - Address address = generateAddressObject(addressSpace, destinationPlan); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(address); - consolePage.openClientsList(address); - assertThat("Link table is not empty!", consolePage.isClientListEmpty()); - int link_count = attachClients(addressSpace, address, defaultCredentials); - selenium.waitUntilPropertyPresent(60, link_count, () -> consolePage.getClientItems().size()); - assertThat(consolePage.getClientItems().size(), is(link_count)); - } - - protected void doTestAddressLinksWithMismatchedAddressResourceNameAndSuffix(AddressSpace addressSpace, String destinationPlan) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - Address address = doCreateAddressWithMismatchedAddressResourceNameAndSuffix(addressSpace, destinationPlan); - consolePage.openClientsList(address); - assertThat("Link table is not empty!", consolePage.isClientListEmpty()); - int link_count = attachClients(addressSpace, address, defaultCredentials); - selenium.waitUntilPropertyPresent(60, link_count, () -> consolePage.getClientItems().size()); - assertThat(consolePage.getClientItems().size(), is(link_count)); - } - - private Address doCreateAddressWithMismatchedAddressResourceNameAndSuffix(AddressSpace addressSpace, String destinationPlan) throws Exception { - Address address = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queues") - .withPlan(destinationPlan) - .endSpec() - .build(); - getResourceManager().setAddresses(address); - return address; - } - - private void doTestSortConnections(AddressSpace addressSpace, SortType sortType, ClientAttacher attacher, Predicate readyCondition, Comparator sortingComparator) throws Exception { - int addressCount = 2; - List
addresses = generateQueueTopicList(addressSpace, "via-web", IntStream.range(0, addressCount)); - - getResourceManager().setAddresses(addresses.toArray(new Address[0])); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - assertEquals(0, consolePage.getConnectionItems().size(), "Unexpected number of connections present before attaching clients"); - - clientsList = attacher.attach(addressSpace, addresses, defaultCredentials); - - selenium.waitUntilPropertyPresent(60, clientsList.size(), () -> consolePage.getConnectionItems().size()); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getConnectionItems().stream() - .allMatch(readyCondition), - Duration.ofSeconds(60), - Duration.ofSeconds(1), - () -> "Failed to wait for connections count"); - - consolePage.sortConnections(sortType, true); - assertSorted("Console failed, items are not sorted by count of senders asc", - consolePage.getConnectionItems(), - sortingComparator); - - consolePage.sortConnections(sortType, false); - assertSorted("Console failed, items are not sorted by count of senders desc", - consolePage.getConnectionItems(), - true, - sortingComparator); - } - - protected void doTestFilterConnectionsByContainerId(AddressSpace addressSpace) throws Exception { - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-via-web")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-via-web") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openConnectionList(addressSpace); - - int connectionCount = 5; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, dest, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount, () -> consolePage.getConnectionItems().size()); - - String containerID = consolePage.getConnectionItems().get(0).getContainerId(); - - consolePage.addConnectionsFilter(FilterType.CONTAINER, containerID); - assertThat(String.format("Console failed, does not contain %d connections", 1), - consolePage.getConnectionItems().size(), is(1)); - - consolePage.removeAllFilters(); - assertThat(String.format("Console failed, does not contain %d connections", connectionCount), - consolePage.getConnectionItems().size(), is(connectionCount)); - } - - protected void doTestFilterClientsByContainerId(AddressSpace addressSpace) throws Exception { - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - getResourceManager().setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openClientsList(address); - - int connectionCount = 2; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, address, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount * 2, () -> consolePage.getClientItems().size()); - - String containerId = consolePage.getClientItems().get(0).getContainerId(); - - consolePage.addClientsFilter(FilterType.CONTAINER, containerId); - assertThat(String.format("Console failed, does not contain %d clients", 1), - consolePage.getClientItems().size(), is(2)); - - consolePage.removeAllFilters(); - - assertThat(String.format("Console failed, does not contain %d clients", connectionCount), - consolePage.getClientItems().size(), is(connectionCount * 2)); - } - - - protected void doTestFilterClientsByName(AddressSpace addressSpace) throws Exception { - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - getResourceManager().setAddresses(address); - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openClientsList(address); - - int connectionCount = 2; - clientsList = new ArrayList<>(); - clientsList.add(getClientUtils().attachConnector(addressSpace, address, connectionCount, 1, 1, defaultCredentials, 360)); - selenium.waitUntilPropertyPresent(60, connectionCount * 2, () -> consolePage.getClientItems().size()); - - String containerId = consolePage.getClientItems().get(0).getName(); - - consolePage.addClientsFilter(FilterType.NAME, containerId); - assertThat(String.format("Console failed, does not contain %d clients", 1), - consolePage.getClientItems().size(), is(1)); - - consolePage.removeAllFilters(); - - assertThat(String.format("Console failed, does not contain %d clients", connectionCount), - consolePage.getClientItems().size(), is(connectionCount * 2)); - } - - protected void doTestGoneAwayPageAfterConnectionClose(AddressSpace addressSpace, ExtensionContext context) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_LARGE_QUEUE); - consolePage.openAddressList(addressSpace); - consolePage.createAddress(address); - clientsList = attachClients(addressSpace, - Collections.singletonList(address), defaultCredentials); - consolePage.switchToConnectionTab(); - selenium.waitUntilPropertyPresent(30, 3, () -> consolePage.getConnectionItems().size()); - consolePage.openConnection(consolePage.getConnectionItems().get(0).getHost()); - Pod pod = kubernetes.getClient().pods() - .inNamespace(SystemtestsKubernetesApps.MESSAGING_CLIENTS).list().getItems().get(0); - kubernetes.deletePod(SystemtestsKubernetesApps.MESSAGING_CLIENTS, pod.getMetadata().getName()); - waitForPodsToTerminate(Collections.singletonList(pod.getMetadata().getUid())); - - consolePage.awaitGoneAwayPage(); - } - - protected void doTestSortConnectionsByContainerId(AddressSpace addressSpace) throws Exception { - doTestSortConnections(addressSpace, SortType.CONTAINER_ID, - this::attachClients, - c -> c.getContainerId() != null, - Comparator.comparing(ConnectionWebItem::getContainerId)); - } - - protected void doTestClientsMetrics(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-in-and-out")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-in-and-out") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(1, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - //this creates 11 senders and 11 receivers in total - clientsList = this.attachClients(addressSpace, Arrays.asList(dest), defaultCredentials); - var senderCount = 11; - var receiverCount = 11; - - selenium.waitUntilPropertyPresent(60, senderCount, () -> consolePage.getAddressItem(dest).getSendersCount()); - selenium.waitUntilPropertyPresent(60, receiverCount, () -> consolePage.getAddressItem(dest).getReceiversCount()); - - assertAll( - () -> assertEquals(receiverCount, consolePage.getAddressItem(dest).getReceiversCount(), - String.format("Console failed, does not contain %d receivers", 10)), - () -> assertEquals(senderCount, consolePage.getAddressItem(dest).getSendersCount(), - String.format("Console failed, does not contain %d senders", 5))); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItem(dest).getMessagesIn() >= 5, - Duration.ofSeconds(180), - Duration.ofSeconds(3), - () -> "Failed to wait for messagesIn/sec to reach 1"); - - TestUtils.waitUntilConditionOrFail(() -> consolePage.getAddressItem(dest).getMessagesOut() >= 5, - Duration.ofSeconds(180), - Duration.ofSeconds(3), - () -> "Failed to wait for messagesOut/sec to reach 1"); - - } - - protected void doTestMessagesStoredMetrics(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - assertEquals(1, consolePage.getAddressItems().size(), "Unexpected number of addresses present before attaching clients"); - - AmqpClient amqpClient = getResourceManager().getAmqpClientFactory().createQueueClient(addressSpace); - var countMessages = 50; - List msgs = TestUtils.generateMessages(countMessages); - Count predicate = new Count<>(msgs.size()); - Future numSent = amqpClient.sendMessages(dest.getSpec().getAddress(), msgs, predicate); - long timeoutMs = countMessages * ClientUtils.ESTIMATE_MAX_MS_PER_MESSAGE; - assertNotNull(numSent, "Sending messages didn't start"); - int actual = 0; - try { - actual = numSent.get(timeoutMs, TimeUnit.MILLISECONDS); - } catch (TimeoutException t) { - logCollector.collectRouterState("runQueueTestSend"); - fail("Sending messages timed out after sending " + predicate.actual()); - } - assertThat("Wrong count of messages sent", actual, is(msgs.size())); - - selenium.waitUntilPropertyPresent(30, countMessages, () -> consolePage.getAddressItem(dest).getMessagesStored()); - - amqpClient.recvMessages(dest.getSpec().getAddress(), countMessages).get(timeoutMs, TimeUnit.MILLISECONDS); - - selenium.waitUntilPropertyPresent(30, 0, () -> consolePage.getAddressItem(dest).getMessagesStored()); - - } - - protected void doTestSortMessagesCount(AddressSpace addressSpace) throws Exception { - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address dest2 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg-2")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg-2") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - Address dest3 = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "queue-stored-msg-3")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("queue-stored-msg-3") - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build(); - - getResourceManager().setAddresses(dest, dest2, dest3); - - var countMessages = 50; - AmqpClient amqpClient = getResourceManager().getAmqpClientFactory().createQueueClient(addressSpace); - - Future numSent1 = amqpClient.sendMessages(dest.getSpec().getAddress(), countMessages); - Future numSent2 = amqpClient.sendMessages(dest2.getSpec().getAddress(), countMessages - 10); - Future numSent3 = amqpClient.sendMessages(dest3.getSpec().getAddress(), countMessages - 30); - - assertThat(numSent1.get(1, TimeUnit.MINUTES), is(countMessages)); - assertThat(numSent2.get(1, TimeUnit.MINUTES), is(countMessages - 10)); - assertThat(numSent3.get(1, TimeUnit.MINUTES), is(countMessages - 30)); - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - selenium.waitUntilPropertyPresent(30, countMessages, () -> consolePage.getAddressItem(dest).getMessagesStored()); - selenium.waitUntilPropertyPresent(30, countMessages - 10, () -> consolePage.getAddressItem(dest2).getMessagesStored()); - selenium.waitUntilPropertyPresent(30, countMessages - 30, () -> consolePage.getAddressItem(dest3).getMessagesStored()); - - consolePage.sortAddresses(SortType.STORED_MESSAGES, true); - assertSorted("Addresses are not sorted by stored messages", consolePage.getAddressItems(), Comparator.comparingInt(AddressWebItem::getMessagesStored)); - consolePage.sortAddresses(SortType.STORED_MESSAGES, false); - assertSorted("Addresses are not sorted by stored messages", consolePage.getAddressItems(), true, Comparator.comparingInt(AddressWebItem::getMessagesStored)); - } - - protected void doTestCanOpenConsolePage(AddressSpace addressSpace, UserCredentials credentials, boolean userAllowed) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), credentials); - consolePage.openConsolePage(); - log.info("User {} successfully authenticated", credentials); - - if (userAllowed) { - consolePage.openAddressList(addressSpace); - } else { - try { - consolePage.openAddressList(addressSpace); - fail("Exception not thrown"); - } catch (NullPointerException ex) { - // PASS - } - - throw new IllegalAccessException(); - } - } - - protected void doTestWithStrangeAddressNames(AddressSpace addressSpace, boolean hyphen, boolean longName, AddressType... types) throws Exception { - String testString = null; - if (hyphen) { - testString = String.join("-", Collections.nCopies(2, "10charhere")); - } - if (longName) { - testString = String.join("", Collections.nCopies(5, "10charhere")); - } - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - - for (AddressType type : types) { - int assert_value = 1; - Address dest; - Address dest_topic = null; - if (type == AddressType.SUBSCRIPTION) { - dest_topic = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "topic-sub" + testString)) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress("topic-sub" + testString) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build(); - log.info("Creating topic for subscription"); - consolePage.createAddress(dest_topic); - dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, testString)) - .endMetadata() - .withNewSpec() - .withType("subscription") - .withAddress(testString) - .withTopic(dest_topic.getSpec().getAddress()) - .withPlan(DestinationPlan.STANDARD_SMALL_SUBSCRIPTION) - .endSpec() - .build(); - assert_value = 2; - } else { - dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(addressSpace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, type.toString() + "-" + testString)) - .endMetadata() - .withNewSpec() - .withType(type.toString()) - .withAddress(type.toString() + "-" + testString) - .withPlan(getDefaultPlan(type)) - .endSpec() - .build(); - assert_value = 1; - } - - consolePage.createAddress(dest); - assertWaitForValue(assert_value, () -> consolePage.getAddressItems().size(), new TimeoutBudget(120, TimeUnit.SECONDS)); - - if (type.equals(AddressType.SUBSCRIPTION)) { - consolePage.deleteAddress(dest_topic); - } - consolePage.deleteAddress(dest); - assertWaitForValue(0, () -> consolePage.getAddressItems().size(), new TimeoutBudget(20, TimeUnit.SECONDS)); - } - } - - protected void doTestValidAddressNames(AddressSpace addressSpace) throws Exception { - - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.openAddressCreationDialog(); - - String validName = "dummy"; - String[] invalidNames = { - "#dummy", - "du#mmy", - "dummy#", - - "*dummy", - "du*mmy", - "dummy*", - - " dummy", - "dum my", - "dummy ", - }; - - for (var name : invalidNames) { - consolePage.fillAddressName(validName); - assertFalse(consolePage.isAddressNameInvalid()); - - consolePage.fillAddressName(name); - assertTrue(consolePage.isAddressNameInvalid(), String.format("Address name %s is not marked as invalid", name)); - } - - String[] validNames = { - "du$mmy", - "du-mmy", - "dummy/foo", - "dum)my", - "dum2my", - - ":dummy", - "du:mmy", - "dummy:", - - ".dummy", - "dum.my", - "dummy.", - }; - - for (String name : validNames) { - consolePage.fillAddressName(validName); - assertFalse(consolePage.isAddressNameInvalid()); - - consolePage.fillAddressName(name); - assertFalse(consolePage.isAddressNameInvalid(), String.format("Address name %s is not marked as valid", name)); - } - } - - protected String getSnippetFirstLine(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.prepareAddressSpaceInstall(addressSpace); - return consolePage.getFirstLineOfDeploymentSnippet().getText(); - } - - protected void getAndExecAddressSpaceDeploymentSnippet(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.prepareAddressSpaceInstall(addressSpace); - String snippet = consolePage.getDeploymentSnippet(); - KubeCMDClient.createCR(Kubernetes.getInstance().getInfraNamespace(), snippet); - } - - protected void getAndExecAddressDeploymentSnippet(AddressSpace addressSpace, Address address) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - consolePage.prepareAddressCreation(address); - String snippet = consolePage.getDeploymentSnippet(); - KubeCMDClient.createCR(Kubernetes.getInstance().getInfraNamespace(), snippet); - } - - protected void doTestErrorDialog(AddressSpace addressSpace) throws Exception { - consolePage = new ConsoleWebPage(selenium, TestUtils.getGlobalConsoleRoute(), clusterUser); - consolePage.openConsolePage(); - consolePage.openAddressList(addressSpace); - Address address = generateAddressObject(addressSpace, DestinationPlan.STANDARD_SMALL_QUEUE); - consolePage.createAddress(address); - consolePage.createAddress(address); - consolePage.waitForErrorDialogToBePresent(); - assertThat("Error dialog is not present after error situation!", - selenium.getWebElement(consolePage::getDangerAlertElement), notNullValue()); - - } - - protected void doTestOpenShiftWithCustomCert() throws Exception { - String openshiftConfigNamespace = "openshift-config"; - String openshiftIngressNamespace = "openshift-ingress"; - String openshiftIngressOperatorNamespace = "openshift-ingress-operator"; - String openshiftAuthenticationNamespace = "openshift-authentication"; - - Map oauthDeploymentLabels = Map.of(LabelKeys.APP, "oauth-openshift"); - Map oauthRouteLabels = Map.of(LabelKeys.APP, "oauth-openshift"); - Map consoleDeploymentLabels = Map.of(LabelKeys.APP, "enmasse", LabelKeys.NAME, "console"); - - Optional oauth = kubernetes.listDeployments(openshiftAuthenticationNamespace, oauthDeploymentLabels).stream().findFirst(); - assertThat(oauth.isPresent(), is(true)); - - Optional oauthRoute = kubernetes.listRoutes(openshiftAuthenticationNamespace, oauthRouteLabels).stream().findFirst(); - assertThat(oauthRoute.isPresent(), is(true)); - - CertPair originalOauthCert = OpenSSLUtil.downloadCert(oauthRoute.get().getSpec().getHost(), 443); - - String customCaCnName = "custom-ca"; - String customIngressSecretName = "custom-ingress"; - String wildcardSan = String.format("*.%s", environment.kubernetesDomain()); - log.info("Wildcard SAN for custom cert: {}", wildcardSan); - try (CertPair ca = OpenSSLUtil.createSelfSignedCert("/O=io.enmasse/CN=MyCA"); - CertPair unsignedCluster = OpenSSLUtil.createSelfSignedCert("/O=io.enmasse//CN=MyCluster"); - CertSigningRequest csr = OpenSSLUtil.createCsr(unsignedCluster); - CertPair cluster = OpenSSLUtil.signCsr(csr, Collections.singletonList(wildcardSan), ca) - ) { - // Steps from https://docs.openshift.com/container-platform/4.3/authentication/certificates/replacing-default-ingress-certificate.html#replacing-default-ingress_replacing-default-ingress - - assertThat(cluster.getCert().canRead(), is(true)); - assertThat(cluster.getKey().canRead(), is(true)); - - ExecutionResultData ingressSecret = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "create", "secret", "tls", customIngressSecretName, - "--namespace", openshiftIngressNamespace, - String.format("--cert=%s", cluster.getCert()), - String.format("--key=%s", cluster.getKey())), true); - assertThat("failed to create ingress secret", ingressSecret.getRetCode(), is(true)); - - ExecutionResultData cmCustomCa = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "create", "configmap", customCaCnName, - "--namespace", openshiftConfigNamespace, - String.format("--from-file=ca-bundle.crt=%s", ca.getCert().getAbsolutePath())), true); - assertThat("failed to create custom-ca configmap", cmCustomCa.getRetCode(), is(true)); - - ExecutionResultData patchProxy = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "proxy/cluster", - "--type=merge", - String.format("--patch={\"spec\":{\"trustedCA\":{\"name\":\"%s\"}}}", customCaCnName)), true); - assertThat("failed to patch proxy/cluster", patchProxy.getRetCode(), is(true)); - - ExecutionResultData patchIngress = Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "ingresscontroller.operator/default", - "--type=merge", - "--namespace", openshiftIngressOperatorNamespace, - String.format("--patch={\"spec\":{\"defaultCertificate\": {\"name\": \"%s\"}}}", customIngressSecretName)), true); - assertThat("failed to patch ingress", patchIngress.getRetCode(), is(true)); - - awaitCertChange(ca, oauth.get(), oauthRoute.get()); - - awaitEnMasseConsoleAvailable("Ensuring console functional after certificate change"); - SeleniumProvider.getInstance().tearDownDrivers(); - SeleniumProvider.getInstance().setupDriver(this.getClass().getSimpleName().toLowerCase().contains("chrome") ? TestUtils.getChromeDriver() : TestUtils.getFirefoxDriver()); - } finally { - Optional bundle = kubernetes.listConfigMaps(Map.of("app", "enmasse")).stream().filter(cm -> "console-trusted-ca-bundle".equals(cm.getMetadata().getName())).findFirst(); - bundle.ifPresent(cm -> log.info("console-trusted-ca-bundle resource version before rollback : {}", cm.getMetadata().getResourceVersion())); - - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "proxy/cluster", - "--type=merge", - "--patch={\"spec\":{\"trustedCA\": null}}"), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "patch", "ingresscontroller.operator/default", - "--type=merge", - "--namespace", openshiftIngressOperatorNamespace, - "--patch={\"spec\":{\"defaultCertificate\": null}}"), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "delete", "configmap", customCaCnName, - "--namespace", openshiftConfigNamespace), false); - Exec.execute(Arrays.asList(kubernetes.getCluster().getKubeCmd(), "delete", "secret", customIngressSecretName, - "--namespace", openshiftIngressNamespace), false); - - - awaitCertChange(originalOauthCert, oauth.get(), oauthRoute.get()); - awaitEnMasseConsoleAvailable("Ensuring console functional after certificate rollback"); - } - } - - private void awaitEnMasseConsoleAvailable(String forWhat) { - TestUtils.waitUntilCondition(forWhat, waitPhase -> { - try { - doTestCanOpenConsolePage(resourcesManager.getSharedAddressSpace(), clusterUser, true); - return true; - } catch (Exception e) { - return false; - } - }, new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - private void awaitCertChange(CertPair expectedCa, Deployment oauthDeployment, Route oauthRoute) { - TestUtils.waitUntilCondition("Awaiting cert change", waitPhase -> { - try { - KubeCMDClient.loginUser(clusterUser.getUsername(), clusterUser.getUsername()); - verifyCertChange(expectedCa, oauthDeployment, oauthRoute); - return true; - } catch (Exception e) { - return false; - } - }, new TimeoutBudget(5, TimeUnit.MINUTES)); - } - - private void verifyCertChange(CertPair ca, Deployment oauthDeployment, Route oauthRoute) throws Exception { - Optional bundle = kubernetes.listConfigMaps(Map.of("app", "enmasse")).stream().filter(cm -> "console-trusted-ca-bundle".equals(cm.getMetadata().getName())).findFirst(); - bundle.ifPresent(cm -> log.info("console-trusted-ca-bundle resource version : {}", cm.getMetadata().getResourceVersion())); - - log.info("Awaiting openshift oauth to be ready again"); - TestUtils.waitForChangedResourceVersion(new TimeoutBudget(1, TimeUnit.MINUTES), oauthDeployment.getMetadata().getResourceVersion(), - () -> { - Optional upd = kubernetes.listDeployments(oauthDeployment.getMetadata().getNamespace(), oauthDeployment.getMetadata().getLabels()).stream().findFirst(); - assertThat(upd.isPresent(), is(true)); - return upd.get().getMetadata().getResourceVersion(); - }); - - KubeCMDClient.awaitRollout(new TimeoutBudget(3, TimeUnit.MINUTES), oauthDeployment.getMetadata().getNamespace(), oauthDeployment.getMetadata().getName()); - - // await for oauth and verify it uses the correct certificate - if (ca != null) { - String oauthHost = oauthRoute.getSpec().getHost(); - TestUtils.waitUntilCondition(String.format("Await for oauth http endpoint to become ready: %s", oauthHost), waitPhase -> { - List curl = Arrays.asList("curl", - "--cacert", ca.getCert().getAbsolutePath(), - "--verbose", String.format("https://%s", oauthHost)); - ExecutionResultData consolePing = Exec.execute(curl, true); - return consolePing.getRetCode(); - }, new TimeoutBudget(3, TimeUnit.MINUTES)); - } - } - - //============================================================================================ - //============================ Help methods ================================================== - //============================================================================================ - - private AddressSpace generateAddressSpaceObject(AddressSpaceType addressSpaceType) { - return new AddressSpaceBuilder() - .withNewMetadata() - .withName("test-address-space-" + addressSpaceType.toString()) - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(addressSpaceType.toString()) - .withPlan(addressSpaceType.toString().equals(AddressSpaceType.BROKERED.toString()) ? - AddressSpacePlans.BROKERED : AddressSpacePlans.STANDARD_MEDIUM) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - } - - private Address generateAddressObject(AddressSpace addressSpace, String destinationPlan) { - return new AddressBuilder() - .withNewMetadata() - .withNamespace(Kubernetes.getInstance().getInfraNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressSpace, "test-queue")) - .endMetadata() - .withNewSpec() - .withAddress("test-queue") - .withType("queue") - .withPlan(destinationPlan) - .endSpec() - .build(); - } - - private List
generateQueueTopicList(AddressSpace addressspace, String infix, IntStream range) { - List
addresses = new ArrayList<>(); - range.forEach(i -> { - if (i % 2 == 0) { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, String.format("topic-%s-%d", infix, i))) - .endMetadata() - .withNewSpec() - .withType("topic") - .withAddress(String.format("topic-%s-%d", infix, i)) - .withPlan(getDefaultPlan(AddressType.TOPIC)) - .endSpec() - .build()); - } else { - addresses.add(new AddressBuilder() - .withNewMetadata() - .withNamespace(addressspace.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(addressspace, String.format("queue-%s-%d", infix, i))) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress(String.format("queue-%s-%d", infix, i)) - .withPlan(getDefaultPlan(AddressType.QUEUE)) - .endSpec() - .build()); - } - }); - return addresses; - } - - /** - * @param addressSpace dest addressspace - * @param destination dest address - * @param userCredentials messaging user credentials - * @return senders + receivers count - * @throws Exception - */ - private int attachClients(AddressSpace addressSpace, Address destination, UserCredentials userCredentials) throws Exception { - final int SENDER_COUNT = 6; - final int RECEIVER_COUNT = 4; - if (addressSpace.getSpec().getPlan().equals(AddressSpacePlans.BROKERED)) { - for (int i = 0; i < SENDER_COUNT; i++) { - getClientUtils().attachSender(addressSpace, destination, userCredentials, 1000, 60000); - if (i < RECEIVER_COUNT) { - getClientUtils().attachReceiver(addressSpace, destination, userCredentials, 1100); - } - } - } else { - getClientUtils().attachConnector(addressSpace, destination, 1, SENDER_COUNT, RECEIVER_COUNT, userCredentials, 60000); - } - return (SENDER_COUNT + RECEIVER_COUNT); - } - - private List attachClients(AddressSpace addressSpace, List
destinations, UserCredentials userCredentials) throws Exception { - List clients = new ArrayList<>(); - for (Address destination : destinations) { - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 6, 1, userCredentials, 60000)); - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 4, 4, userCredentials, 60000)); - clients.add(getClientUtils().attachConnector(addressSpace, destination, 1, 1, 6, userCredentials, 60000)); - } - Thread.sleep(5000); - return clients; - } - - private void assertAddressType(String message, List allItems, AddressType type) { - assertThat(message, getAddressProperty(allItems, (item -> item.getType().contains(type.toString()))).size(), is(allItems.size())); - } - - private void assertAddressName(String message, List allItems, String subString) { - assertThat(message, getAddressProperty(allItems, (item -> item.getAddress().contains(subString))).size(), is(allItems.size())); - } - - private List getConnectionProperty(List allItems, Predicate f) { - return allItems.stream().filter(f).collect(Collectors.toList()); - } - - private List getAddressProperty(List allItems, Predicate f) { - return allItems.stream().filter(f).collect(Collectors.toList()); - } - - private void waitUntilAddressSpaceActive(AddressSpace addressSpace) throws Exception { - String name = addressSpace.getMetadata().getName(); - resourcesManager.waitForAddressSpaceReady(addressSpace); - Boolean active = Optional.ofNullable(selenium.waitUntilItemPresent(60, () -> consolePage.getAddressSpaceItem(addressSpace))) - .map(webItem -> webItem.getStatus().contains("Active")) - .orElseGet(() -> { - log.error("AddressSpaceWebItem {} not present", name); - return false; - }); - assertTrue(active, String.format("Address space %s not marked active in UI within timeout", name)); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java b/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java deleted file mode 100644 index 88c88ba97e0..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/bases/web/WebSocketBrowserTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2018, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.bases.web; - - -import io.enmasse.address.model.Address; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.shared.ITestBaseShared; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.selenium.SeleniumProvider; -import io.enmasse.systemtest.selenium.page.RheaWebPage; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import org.junit.jupiter.api.BeforeEach; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public abstract class WebSocketBrowserTest extends TestBase implements ITestBaseShared { - - private RheaWebPage rheaWebPage; - - @BeforeEach - public void setUpWebConsoleTests() throws Exception { - rheaWebPage = new RheaWebPage(SeleniumProvider.getInstance()); - resourcesManager.deleteAddresses(getSharedAddressSpace()); - } - - //============================================================================================ - //============================ do test methods =============================================== - //============================================================================================ - - protected void doWebSocketSendReceive(Address destination) throws Exception { - resourcesManager.setAddresses(destination); - int count = 10; - - rheaWebPage.sendReceiveMessages(AddressSpaceUtils.getMessagingWssRoute(getSharedAddressSpace()).toString(), destination.getSpec().getAddress(), - count, defaultCredentials, AddressSpaceType.valueOf(getSharedAddressSpace().getSpec().getType().toUpperCase())); - assertTrue(rheaWebPage.checkCountMessage(count * 2), "Browser client didn't sent and received all messages"); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java b/systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java similarity index 98% rename from systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java rename to systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java index 8503b3c9191..0e031eb2df8 100644 --- a/systemtests/src/test/java/io/enmasse/systemtest/resources/CliOutputDataTest.java +++ b/systemtests/src/test/java/io/enmasse/systemtest/framework/CliOutputDataTest.java @@ -2,9 +2,10 @@ * Copyright 2020, EnMasse authors. * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). */ -package io.enmasse.systemtest.resources; +package io.enmasse.systemtest.framework; import io.enmasse.systemtest.TestTag; +import io.enmasse.systemtest.resources.CliOutputData; import io.enmasse.systemtest.resources.CliOutputData.CliOutputDataType; import org.junit.jupiter.api.Tag; diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java deleted file mode 100644 index c64c24b3348..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/CredentialsTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import io.enmasse.systemtest.TestTag; -import io.vertx.core.json.JsonObject; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@Tag(TestTag.FRAMEWORK) -public class CredentialsTest { - - @Test - void testCreateSecret() { - var creds = JsonObject.mapFrom(CredentialsRegistryClient.createCredentialsObject("auth-id", "foo", null)); - - var secrets = creds.getJsonArray("secrets"); - assertNotNull(secrets); - var secret = secrets.getJsonObject(0); - assertNotNull(secret); - - assertNotNull(secret.getBinary("pwd-hash")); - assertNotNull(secret.getBinary("salt")); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java deleted file mode 100644 index 8c52eb2f6b1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceCertificateManagerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static io.enmasse.systemtest.TestTag.FRAMEWORK; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.security.cert.X509Certificate; -import java.time.Duration; -import java.time.Instant; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.iot.DeviceCertificateManager.Device; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; - -@Tag(FRAMEWORK) -public class DeviceCertificateManagerTest { - - @Test - public void testRsa() throws Exception { - final DeviceCertificateManager mgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("CN=foo,OU=bar,O=baz")); - - final X509Certificate cert = mgr.getCertificate(); - assertNotNull(cert); - - final Device device = mgr.createDevice("dev1", Instant.now(), Duration.ofDays(90)); - assertNotNull(device); - assertNotNull(device.getKey()); - assertNotNull(device.getCertificate()); - } - - @Test - public void testEc() throws Exception { - final DeviceCertificateManager mgr = new DeviceCertificateManager(Mode.EC, new X500Principal("CN=foo,OU=bar,O=baz")); - - final X509Certificate cert = mgr.getCertificate(); - assertNotNull(cert); - - final Device device = mgr.createDevice("dev1", Instant.now(), Duration.ofDays(90)); - assertNotNull(device); - assertNotNull(device.getKey()); - assertNotNull(device.getCertificate()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java deleted file mode 100644 index 0b024785756..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/DeviceSupplier.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import java.util.Objects; - -import org.junit.jupiter.params.provider.MethodSource; - -import io.enmasse.systemtest.iot.IoTTestSession.Device; - -/** - * A supplier for devices. Required due to an issue in Surefire. - *

- * This is a workaround for SUREFIRE-1799, which silently drops unit tests in case - * there is an exception being thrown in a method of a {@link MethodSource}. As we - * create {@link Device}s for parametrized tests and creation of devices might fail, - * that will be an issue. - *

- * The idea is to delay the actual execution of the device creation until it - * is running in the actual test case. So instead of creating devices, we create - * code that creates devices. The call to the {@link #get()} method should perform - * the actual device creation, and it may fail, which is reported as a test failure. - *

- * @see SUREFIRE-1799 - */ -@FunctionalInterface -public interface DeviceSupplier { - - public Device get() throws Exception; - - /** - * Allows to override the output of the {@link #toString()} method. - *

- * This may be used to provide a stable name for parameterized test. - * - * @implNote This was originally part of the {@link Device} class. Due to - * SUREFIRE-1799 this code currently lives here. - * - * @param name The value to report from {@link #toString()}. - * @return The new instance, reporting the provided name. - */ - static DeviceSupplier named(final String name, final DeviceSupplier supplier) { - - Objects.requireNonNull(name); - Objects.requireNonNull(supplier); - - return new DeviceSupplier() { - - @Override - public Device get() throws Exception { - return supplier.get(); - } - - @Override - public String toString() { - return name; - } - }; - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java deleted file mode 100644 index f5b600013c1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/IoTTestSessionTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static io.enmasse.systemtest.TestTag.FRAMEWORK; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; - -@Tag(FRAMEWORK) -public class IoTTestSessionTest { - - @Test - public void testNameInDefaultConfig() throws Exception { - var config = IoTTestSession.createDefaultConfig("default-ns", true).build(); - - assertDefaultConfig(config); - } - - @Test - public void testNameInDefaultConfigAfterChange() throws Exception { - var configBuilder = IoTTestSession.createDefaultConfig("default-ns", true); - - assertDefaultConfig(configBuilder.build()); - - for (Adapter adapter : Adapter.values()) { - configBuilder = adapter.disable(configBuilder); - } - configBuilder = HTTP.enable(configBuilder); - - assertDefaultConfig(configBuilder.build()); - - } - - private void assertDefaultConfig(IoTConfig config) { - assertNotNull(config); - - assertNotNull(config.getMetadata()); - assertEquals("default", config.getMetadata().getName()); - assertEquals("default-ns", config.getMetadata().getNamespace()); - } - - @Test - public void testEnableAdapter() throws Exception { - AtomicBoolean called = new AtomicBoolean(); - - IoTTestSession - .create("default-ns", true) - .adapters(Adapter.HTTP) - .config(configBuilder -> { - - var config = configBuilder.build(); - - assertNotNull(config.getSpec()); - assertNotNull(config.getSpec().getAdapters()); - - assertNotNull(config.getSpec().getAdapters().getHttp()); - assertEquals(Boolean.TRUE, config.getSpec().getAdapters().getHttp().getEnabled()); - - assertNotNull(config.getSpec().getAdapters().getMqtt()); - assertEquals(Boolean.FALSE, config.getSpec().getAdapters().getMqtt().getEnabled()); - - called.set(true); - - }); - - assertTrue(called.get()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java deleted file mode 100644 index 60aae1db950..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/KeyStoreCreatorTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Duration; -import java.time.Instant; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; - -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; - -@Tag(TestTag.FRAMEWORK) -public class KeyStoreCreatorTest { - - @Test - public void testBasicRsa() throws Exception { - var mgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - KeyStoreCreator.from(device.getKey().getPrivate(), device.getCertificate()); - } - - @Test - public void testBasicEc() throws Exception { - var mgr = new DeviceCertificateManager(Mode.EC, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - KeyStoreCreator.from(device.getKey().getPrivate(), device.getCertificate()); - } - - @ParameterizedTest(name = "testToByteArray-{0}") - @EnumSource(Mode.class) - public void testToByteArray(final Mode mode) throws Exception { - var mgr = new DeviceCertificateManager(mode, new X500Principal("O=EnMasse,C=IO")); - var device = mgr.createDevice("foo", Instant.now(), Duration.ofDays(90)); - - byte[] bytes = KeyStoreCreator.toByteArray(device.getKey().getPrivate(), device.getCertificate()); - - assertNotNull(bytes); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java deleted file mode 100644 index a74c23fa442..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/MessageSendTesterTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.nio.charset.StandardCharsets; -import java.util.Arrays; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.TestTag; -import io.vertx.core.json.JsonObject; - -@Tag(TestTag.FRAMEWORK) -public class MessageSendTesterTest { - - @Test - public void testFillingEmpty() { - final JsonObject json = new JsonObject(); - var result = MessageSendTester.fillWithPayload(json, 1024); - assertEquals(1024, result.length()); - } - - @Test - public void testFillUtf8() { - final JsonObject json = new JsonObject(); - json.put("some-utf-8", "\u1F926"); - var result = MessageSendTester.fillWithPayload(json, 1024); - assertEquals(1024, result.length()); - } - - @Test - public void testFillingNonEmpty() { - - final int fixedLength = "{\"init\":\"\"}".getBytes(StandardCharsets.UTF_8).length; - - for (int initialLength = fixedLength; initialLength < 1024; initialLength++) { - - final char init[] = new char[initialLength - fixedLength]; - Arrays.fill(init, 'b'); - final String initValue = String.valueOf(init); - - for (int expectedLength = initialLength + MessageSendTester.FIXED_JSON_EXTRA_SIZE + 1; expectedLength < 1024; expectedLength++) { - - final JsonObject json = new JsonObject(); - json.put("init", initValue); - - var result = MessageSendTester.fillWithPayload(json, expectedLength); - assertEquals(expectedLength, result.length()); - - } - - } - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java deleted file mode 100644 index 277a841e8e9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/StandardIoTTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot; - -import java.util.List; - -public interface StandardIoTTests extends IoTTests { - - /** - * Test the test session. - */ - public IoTTestSession getSession(); - - /** - * Get a list of devices which must succeed. - */ - public List getDevices(); - - /** - * Get a list of devices which must fail. - */ - public List getInvalidDevices(); - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java deleted file mode 100644 index 6796c8ad454..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/http/StandardIoTHttpTests.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.http; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.HttpAdapterClient.causedBy; -import static io.enmasse.systemtest.iot.HttpAdapterClient.ResponseException.statusCode; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import javax.net.ssl.SSLHandshakeException; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.StandardIoTTests; - -public interface StandardIoTHttpTests extends StandardIoTTests { - - static final Logger log = LoggerFactory.getLogger(StandardIoTHttpTests.class); - - /** - * Single telemetry message with attached consumer. - */ - @Tag(ACCEPTANCE) - @ParameterizedTest(name = "testHttpTelemetrySingle-{0}") - @MethodSource("getDevices") - default void testHttpTelemetrySingle(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(1) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test a single event message. - *
- * Send a single message, no consumer attached. The message gets delivered - * when the consumer attaches. - */ - @ParameterizedTest(name = "testHttpEventSingle-{0}") - @MethodSource("getDevices") - default void testHttpEventSingle(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(1) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Test a batch of telemetry messages, consumer is started before sending. - *
- * This is the normal telemetry case. - */ - @ParameterizedTest(name = "testHttpTelemetryBatch50-{0}") - @MethodSource("getDevices") - default void testHttpTelemetryBatch50(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test a batch of events, having no consumer attached. - *
- * As events get buffered by the broker, there is no requirement to start - * a consumer before sending the messages. However when the consumer is - * attached, it should receive those messages. - */ - @ParameterizedTest(name = "testHttpEventBatch5After-{0}") - @MethodSource("getDevices") - default void testHttpEventBatch5After(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .additionalSendTimeout(Duration.ofSeconds(10)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Test a batch of events, starting the consumer before sending. - *
- * This is the default use case with events, and should simply work - * as with telemetry. - */ - @ParameterizedTest(name = "testHttpEventBatch5Before-{0}") - @MethodSource("getDevices") - default void testHttpEventBatch5Before(final DeviceSupplier device) throws Exception { - - try (HttpAdapterClient client = device.get().createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ZERO) - .additionalSendTimeout(Duration.ofSeconds(10)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test for an invalid device. - *
- * With an invalid device, no messages must pass. - */ - @ParameterizedTest(name = "testHttpDeviceFails-{0}") - @MethodSource("getInvalidDevices") - default void testHttpDeviceFails(final DeviceSupplier deviceSupplier) throws Exception { - - log.info("Testing invalid devices, the following exception may be expected"); - var device = deviceSupplier.get(); - - /* - * We test an invalid device by trying to send either telemetry or event messages. - * Two separate connections, and more than one message. - */ - - try (HttpAdapterClient client = device.createHttpAdapterClient()) { - client.suppressExceptions( - statusCode(401) - .or(causedBy(SSLHandshakeException.class))); - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } - - try (HttpAdapterClient client = device.createHttpAdapterClient()) { - client.suppressExceptions( - statusCode(401) - .or(causedBy(SSLHandshakeException.class))); - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::send) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } - - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java deleted file mode 100644 index f54a937838f..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/AbstractMaxPayloadSizeTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated; - -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.MessageSendTester.Type; - -public abstract class AbstractMaxPayloadSizeTest extends TestBase implements ITestIoTIsolated { - - protected abstract Adapter adapter(); - - protected abstract Sender sender(Device device) throws Exception; - - /** - * Reduce the payload by this amount of bytes. - *

- * This is required by e.g. the MQTT protocol, as the topic name counts against the total length of - * the MQTT payload. - * - * @param type the type to send. - * - * @return The number of bytes to remove from the payload. - */ - protected int reducePayloadBy(final Type type) { - return 0; - } - - @Test - public void testDecreasedMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .config(config -> config - .editOrNewSpec() - .editOrNewAdapters() - .editOrNewDefaults() - .withMaxPayloadSize(256) - .endDefaults() - .endAdapters() - .endSpec()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - // we expect the sending to fail, due to timeouts, as the payload exceeds the maximum - - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize(1024 - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - }); - - } - - @Test - public void testIncreasedMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .config(config -> config - .editOrNewSpec() - .editOrNewAdapters() - .editOrNewDefaults() - .withMaxPayloadSize(16 * 1024) - .endDefaults() - .endAdapters() - .endSpec()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize((16 * 1024) - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - - @Test - public void testStandardMaxPayloadDefault() throws Exception { - - IoTTestSession - .createDefault() - .adapters(adapter()) - .run(session -> { - - var device = session - .newDevice("4711") - .register() - .setPassword("auth-1", "123456"); - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .payloadSize(1024 - reducePayloadBy(MessageSendTester.Type.TELEMETRY)) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(sender(device)) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java deleted file mode 100644 index 8cdc076141a..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/IoTProjectManagedTest.java +++ /dev/null @@ -1,421 +0,0 @@ -/* - * Copyright 2018-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static io.enmasse.user.model.v1.Operation.recv; -import static io.enmasse.user.model.v1.Operation.send; -import static java.time.Duration.ofMinutes; -import static java.util.Arrays.asList; -import static java.util.EnumSet.of; -import static java.util.Optional.ofNullable; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.hamcrest.core.AllOf.allOf; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.hamcrest.Matcher; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceStatus; -import io.enmasse.address.model.AddressStatus; -import io.enmasse.address.model.KubeUtil; -import io.enmasse.address.model.Phase; -import io.enmasse.iot.model.v1.DoneableIoTProject; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectList; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthorization; -import io.enmasse.user.model.v1.UserStatus; -import io.fabric8.kubernetes.api.model.Doneable; -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.OwnerReference; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -class IoTProjectManagedTest extends TestBase implements ITestIoTIsolated { - private final static Logger log = CustomLogger.getLogger(); - - @FunctionalInterface - interface ProjectModificator { - /** - * Modify a project - * - * @param timeout The timeout budget the operation has available. - * @param project The project to work with. It is an provisioned project, which already passed a - * call to {@link IoTProjectManagedTest#assertManaged(IoTProject)}. - * @return {@code true} if the state has been change and a final call to - * {@link IoTProjectManagedTest#assertManaged(IoTProject)} to be performed. - */ - boolean modify(TimeoutBudget timeout, IoTProject project) throws Exception; - } - - private Kubernetes kubernetes = Kubernetes.getInstance(); - - private MixedOperation> projectClient; - - @BeforeEach - void createIoTClient() { - this.projectClient = this.kubernetes.getIoTProjectClient(IOT_PROJECT_NAMESPACE); - } - - /** - * Simply create a project and directly test it. - */ - @Test - @Tag(SMOKE) - @Tag(ACCEPTANCE) - void testCreate() throws Exception { - // run a default test, with no modifications - doTestAddressSpaceWithModifications(ofDuration(ofMinutes(5)), (timeout, project) -> false); - } - - /** - * Delete a resource and wait for it to be re-created properly. - * - * @param The resource type. - * @param The list type of the resource. - * @param The {@link Doneable} type. - * @param project The IoT project to process. - * @param clazz The class instance of the resource type. - * @param name The kubernetes name of the resource. - * @param basicClient The basic resource client. Does not need to be namespaced. - * @param phaseExtractor The function which extracts the phase information. - */ - ProjectModificator deleteAndWaitResource(final Class clazz, final Function nameExtractor, - final MixedOperation> basicClient, final Function> phaseExtractor) { - - return (timeout, project) -> { - - final var name = nameExtractor.apply(project); - final var className = clazz.getSimpleName(); - final var client = basicClient.inNamespace(IOT_PROJECT_NAMESPACE); - - // get the current address space - - final var namedClient = client.withName(name); - final var currentResource = namedClient.get(); - assertNotNull(currentResource, () -> String.format("Unable to find resource - type: %s, name: '%s'", className, name)); - - // remember its ID - - final String originalId = currentResource.getMetadata().getUid(); - assertNotNull(originalId); - - // delete it - - client.withName(name).delete(); - - // now wait for it to be re-created - - TestUtils.waitUntilConditionOrFail(() -> { - - var current = namedClient.get(); - if (current == null) { - log.info("{} is still missing", className); - return false; - } - if (originalId.equals(current.getMetadata().getUid())) { - log.info("{} has still the same ID", className); - // still the same object - return false; - } - - // get current phase - final var phase = phaseExtractor.apply(current); - if (!phase.isPresent()) { - log.info("{} no phase information", className); - return false; - } - - if (phase.get() != Phase.Active) { - log.info("{} is not ready yet: {}", className, phase.get()); - return false; - } - - return true; - }, timeout.remaining(), Duration.ofSeconds(10), () -> className + " did not get re-created"); - - // and wait for the IoT project to become ready again - - var projectAccess = kubernetes.getIoTProjectClient(project.getMetadata().getNamespace()).withName(project.getMetadata().getName()); - TestUtils.waitUntilConditionOrFail(() -> { - var current = projectAccess.get(); - - if (current == null) { - log.info("IoTProject missing"); - return false; - } - - if (current.getStatus() == null || current.getStatus().getPhase() == null) { - log.info("IoTProject is missing status information"); - return false; - } - - if (!current.getStatus().getPhase().equals("Active")) { - return false; - } - - return true; - }, timeout.remaining(), Duration.ofSeconds(10), () -> "IoTProject failed to switch back to 'Active'"); - - return true; - }; - } - - /** - * Test deleting the whole address space. - */ - @Test - void testDeleteAddressSpace() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(15)), - deleteAndWaitResource( - AddressSpace.class, - project -> project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - kubernetes.getAddressSpaceClient(), - addressSpace -> ofNullable(addressSpace).map(AddressSpace::getStatus).map(AddressSpaceStatus::getPhase))); - } - - /** - * Test deleting the telememtry address. - */ - @Test - void testDeleteTelemetryAddress() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(10)), - deleteAndWaitResource( - Address.class, - project -> KubeUtil.sanitizeForGo( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - "telemetry/" + project.getStatus().getTenantName()), - kubernetes.getAddressClient(), - address -> ofNullable(address).map(Address::getStatus).map(AddressStatus::getPhase))); - } - - /** - * Test deleting the event address. - *
- * The event address is expected to be backed by a brokered address. Thus is might behave - * differently than the others. - */ - @Test - void testDeleteEventAddress() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(15)), - deleteAndWaitResource( - Address.class, - project -> KubeUtil.sanitizeForGo( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - "event/" + project.getStatus().getTenantName()), - kubernetes.getAddressClient(), - address -> ofNullable(address).map(Address::getStatus).map(AddressStatus::getPhase))); - } - - /** - * Test deleting the adapter user. - */ - @Test - void testDeleteAdapterUser() throws Exception { - doTestAddressSpaceWithModifications( - ofDuration(ofMinutes(10)), - deleteAndWaitResource( - User.class, - project -> project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName() - + "." - + project.getStatus().getDownstreamEndpoint().getUsername(), - kubernetes.getUserClient(), - user -> ofNullable(user).map(User::getStatus).map(UserStatus::getPhase))); - } - - void doTestAddressSpaceWithModifications(final TimeoutBudget timeout, final ProjectModificator modificator) throws Exception { - - isolatedIoTManager.createIoTConfig(IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build()); - - final String addressSpaceName = "managed-address-space"; - final String iotProjectName = "iot-project-managed"; - - IoTProject project = IoTUtils.getBasicIoTProjectObject(iotProjectName, addressSpaceName, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - LOGGER.warn("NAMESPACE EXISTS? {}, {}", project.getMetadata().getNamespace(), kubernetes.namespaceExists(project.getMetadata().getNamespace())); - isolatedIoTManager.createIoTProject(project); // waiting until ready - IoTProject created = this.projectClient.withName(iotProjectName).get(); - - assertNotNull(created); - assertEquals(IOT_PROJECT_NAMESPACE, created.getMetadata().getNamespace()); - assertEquals(project.getMetadata().getName(), created.getMetadata().getName()); - assertEquals( - project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), - created.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - - assertManaged(created); - - if (modificator.modify(timeout, created)) { - created = this.projectClient.withName(iotProjectName).get(); - assertNotNull(created); - assertManaged(created); - } - } - - private static void assertAddressType(final Address address, final AddressType type, final String plan) { - assertEquals(type.toString(), address.getSpec().getType()); - assertEquals(plan, address.getSpec().getPlan()); - } - - private void assertManaged(IoTProject project) throws Exception { - // address spaces - AddressSpace addressSpace = - isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - assertEquals(project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName(), addressSpace.getMetadata().getName()); - assertEquals(AddressSpaceType.STANDARD.toString(), addressSpace.getSpec().getType()); - assertEquals(AddressSpacePlans.STANDARD_SMALL, addressSpace.getSpec().getPlan()); - assertEquals(Phase.Active, addressSpace.getStatus().getPhase()); - - // addresses - // {event/control/command/command_response/telemetry}/"project-namespace"."project-name" - final String addressSuffix = "/" + project.getMetadata().getNamespace() + "." + project.getMetadata().getName(); - final List

addresses = AddressUtils.getAddresses(addressSpace); - // assert that we have the right number of addresses - assertEquals(5, addresses.size()); - // assert that all addresses have the project set as owner - assertEquals(5, addresses.stream() - .map(Address::getMetadata) - .map(ObjectMeta::getOwnerReferences) - .flatMap(List::stream) - .filter(reference -> isOwner(project, reference)) - .count()); - - int correctAddressesCounter = 0; - for (Address address : addresses) { - - final String addressName = address.getSpec().getAddress(); - - if (addressName.equals(IOT_ADDRESS_EVENT + addressSuffix)) { - - assertAddressType(address, AddressType.QUEUE, DestinationPlan.STANDARD_SMALL_QUEUE); - correctAddressesCounter++; - - } else if (addressName.equals(IOT_ADDRESS_CONTROL + addressSuffix) - || addressName.equals(IOT_ADDRESS_TELEMETRY + addressSuffix) - || addressName.equals(IOT_ADDRESS_COMMAND + addressSuffix) - || addressName.equals(IOT_ADDRESS_COMMAND_RESPONSE + addressSuffix)) { - - assertAddressType(address, AddressType.ANYCAST, DestinationPlan.STANDARD_SMALL_ANYCAST); - correctAddressesCounter++; - - } - - assertEquals(Phase.Active, address.getStatus().getPhase()); - - } - assertEquals(5, correctAddressesCounter, "There are incorrect IoT addresses " + addresses); - - // username "adapter" - // name "project-address-space"+".adapter" - User user = isolatedIoTManager.getUser(addressSpace, "adapter-" + project.getMetadata().getUid()); - assertNotNull(user); - assertEquals(1, user.getMetadata().getOwnerReferences().size()); - assertTrue(isOwner(project, user.getMetadata().getOwnerReferences().get(0))); - - final List authorizations = user.getSpec().getAuthorization(); - - assertThat(authorizations, hasSize(3)); - - assertThat(authorizations, containsInAnyOrder( - asList( - assertAdapterAuthorization(of(send), expandAddresses(addressSuffix, IOT_ADDRESS_TELEMETRY, IOT_ADDRESS_EVENT, IOT_ADDRESS_COMMAND_RESPONSE)), - assertAdapterAuthorization(of(recv), expandAddresses(addressSuffix, IOT_ADDRESS_COMMAND)), - assertAdapterAuthorization(of(recv, send), expandAddresses(addressSuffix, IOT_ADDRESS_CONTROL))))); - } - - /** - * Assert an authorization entry. - * - * @param operations The expected operations. - * @param addresses The expected addresses. - * @return A matcher, asserting the entry. - */ - private static Matcher assertAdapterAuthorization(final Set operations, final Set addresses) { - - return allOf(asList( - - hasProperty("operations", containsInAnyOrder(operations.toArray(Operation[]::new))), - hasProperty("addresses", containsInAnyOrder(addresses.toArray(String[]::new))) - - )); - - } - - /** - * Expand addresses to match ACLs. - * - * @param addressSuffix The "suffix" (tenant) of the address. - * @return A set of all addresses. - */ - private static Set expandAddresses(final String addressSuffix, final String... baseAddresses) { - - return Arrays - .stream(baseAddresses) - .flatMap(address -> { - return Stream.of( - address + addressSuffix, - address + addressSuffix + "/*"); - }) - - .collect(Collectors.toSet()); - - } - - /** - * Test if the project is the owner the reference points to. - * - * @param project The project to check for. - * @param ownerReference The reference to check. - * @return {@code true} if the reference points to the project. - */ - private boolean isOwner(final IoTProject project, final OwnerReference ownerReference) { - return ownerReference.getKind().equals(IoTProject.KIND) && - project.getMetadata().getName().equals(ownerReference.getName()); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java deleted file mode 100644 index bf470525fc2..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/MultipleProjectsTest.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; - -import java.net.HttpURLConnection; -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.eclipse.paho.client.mqttv3.IMqttClient; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.slf4j.Logger; - -import io.enmasse.address.model.AddressSpace; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.TestTag; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTProjectTestContext; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.mqtt.MqttClientFactory; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.time.WaitPhase; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.enmasse.user.model.v1.Operation; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserAuthenticationType; -import io.enmasse.user.model.v1.UserAuthorizationBuilder; -import io.enmasse.user.model.v1.UserBuilder; - -@Tag(TestTag.SMOKE) -class MultipleProjectsTest extends TestBase implements ITestIoTIsolated { - private static Logger log = CustomLogger.getLogger(); - private DeviceRegistryClient registryClient; - private CredentialsRegistryClient credentialsClient; - - private int numberOfProjects = 2; - private List projects = new ArrayList<>(); - - @BeforeEach - void initEnv() throws Exception { - IoTConfig iotConfig = IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - isolatedIoTManager.createIoTConfig(iotConfig); - - Endpoint deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - registryClient = new DeviceRegistryClient(deviceRegistryEndpoint); - credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint); - - for (int i = 1; i <= numberOfProjects; i++) { - String projectName = String.format("project-%s", i); - - kubernetes.createNamespace(projectName); - - IoTProject project = IoTUtils.getBasicIoTProjectObject(projectName, projectName, - projectName, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(project); - IoTProjectTestContext ctx = new IoTProjectTestContext(projectName, project); - - configureDeviceSide(ctx); - - configureAmqpSide(ctx); - - projects.add(ctx); - } - } - - @AfterEach - void cleanEnv(ExtensionContext context) throws Exception { - for (IoTProjectTestContext ctx : projects) { - cleanDeviceSide(ctx); - cleanAmqpSide(ctx); - } - } - - @Test - @Tag(ACCEPTANCE) - void testMultipleProjects() throws Exception { - - for (final IoTProjectTestContext ctx : projects) { - try (var http = ctx.getHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(ctx.getAmqpClient(), IoTUtils.getTenantId(ctx.getProject()))) - .sender(http::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .consumerFactory(ConsumerFactory.of(ctx.getAmqpClient(), IoTUtils.getTenantId(ctx.getProject()))) - .sender(http::send) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - } - - } - - private void configureAmqpSide(IoTProjectTestContext ctx) throws Exception { - AddressSpace addressSpace = isolatedIoTManager.getAddressSpace(ctx.getNamespace(), - ctx.getProject().getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()); - User amqpUser = configureAmqpUser(ctx.getProject(), addressSpace); - ctx.setAmqpUser(amqpUser); - AmqpClient amqpClient = configureAmqpClient(addressSpace, amqpUser); - ctx.setAmqpClient(amqpClient); - } - - private User configureAmqpUser(IoTProject project, AddressSpace addressSpace) { - String tenant = IoTUtils.getTenantId(project); - - User amqpUser = new UserBuilder() - - .withNewMetadata() - .withName(String.format("%s.%s", addressSpace.getMetadata().getName(), project.getMetadata().getName())) - .endMetadata() - - .withNewSpec() - .withUsername(UUID.randomUUID().toString()) - .withNewAuthentication() - .withPassword(Base64.getEncoder().encodeToString(UUID.randomUUID().toString().getBytes(StandardCharsets.UTF_8))) - .withType(UserAuthenticationType.password) - .endAuthentication() - .withAuthorization(Collections.singletonList(new UserAuthorizationBuilder() - .withAddresses(IOT_ADDRESS_TELEMETRY + "/" + tenant, - IOT_ADDRESS_TELEMETRY + "/" + tenant + "/*", - IOT_ADDRESS_EVENT + "/" + tenant, - IOT_ADDRESS_EVENT + "/" + tenant + "/*") - .withOperations(Operation.recv) - .build())) - .endSpec() - .build(); - kubernetes.getUserClient(project.getMetadata().getNamespace()).create(amqpUser); - - return amqpUser; - } - - private AmqpClient configureAmqpClient(AddressSpace addressSpace, User user) throws Exception { - LOGGER.warn("Amqp factory: " + getAmqpClientFactory()); - AmqpClient amqpClient = getAmqpClientFactory().createQueueClient(addressSpace); - amqpClient.getConnectOptions() - .setUsername(user.getSpec().getUsername()) - .setPassword(new String(Base64.getDecoder().decode(user.getSpec().getAuthentication().getPassword()))); - return amqpClient; - } - - private void cleanAmqpSide(IoTProjectTestContext ctx) throws Exception { - ctx.getAmqpClient().close(); - var userClient = kubernetes.getUserClient(ctx.getNamespace()); - userClient.withName(ctx.getAmqpUser().getMetadata().getName()).cascading(true).delete(); - } - - private void configureDeviceSide(IoTProjectTestContext ctx) throws Exception { - String tenant = IoTUtils.getTenantId(ctx.getProject()); - ctx.setDeviceId(UUID.randomUUID().toString()); - ctx.setDeviceAuthId(UUID.randomUUID().toString()); - ctx.setDevicePassword(UUID.randomUUID().toString()); - registryClient.registerDevice(tenant, ctx.getDeviceId()); - credentialsClient.addCredentials(tenant, ctx.getDeviceId(), ctx.getDeviceAuthId(), ctx.getDevicePassword(), null, HttpURLConnection.HTTP_NO_CONTENT); - Endpoint httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - ctx.setHttpAdapterClient(new HttpAdapterClient(httpAdapterEndpoint, ctx.getDeviceAuthId(), tenant, ctx.getDevicePassword())); - IMqttClient mqttAdapterClient = new MqttClientFactory.Builder() - .clientId(ctx.getDeviceId()) - .endpoint(kubernetes.getExternalEndpoint("iot-mqtt-adapter")) - .usernameAndPassword(ctx.getDeviceAuthId() + "@" + tenant, ctx.getDevicePassword()) - .mqttConnectionOptions(options -> { - options.setAutomaticReconnect(true); - options.setConnectionTimeout(60); - options.setHttpsHostnameVerificationEnabled(false); - }) - .create(); - TestUtils.waitUntilCondition("Successfully connect to mqtt adapter", phase -> { - try { - mqttAdapterClient.connect(); - return true; - } catch (MqttException mqttException) { - if (phase == WaitPhase.LAST_TRY) { - log.error("Error waiting to connect mqtt adapter", mqttException); - } - return false; - } - }, new TimeoutBudget(1, TimeUnit.MINUTES)); - log.info("Connection to mqtt adapter succeeded"); - ctx.setMqttAdapterClient(mqttAdapterClient); - } - - private void cleanDeviceSide(IoTProjectTestContext ctx) throws Exception { - String tenant = IoTUtils.getTenantId(ctx.getProject()); - String deviceId = ctx.getDeviceId(); - credentialsClient.deleteAllCredentials(tenant, deviceId); - registryClient.deleteDeviceRegistration(tenant, deviceId); - registryClient.getDeviceRegistration(tenant, deviceId, HttpURLConnection.HTTP_NOT_FOUND); - ctx.getHttpAdapterClient().close(); - ctx.getMqttAdapterClient().close(); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java deleted file mode 100644 index 0dcbe0bab1b..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/SimpleK8sDeployTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated; - -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; -import static java.util.Collections.singletonMap; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import io.enmasse.iot.model.v1.CommonAdapterContainersBuilder; -import io.enmasse.iot.model.v1.ContainerConfigBuilder; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.JavaContainerConfigBuilder; -import io.enmasse.systemtest.Environment; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.condition.Kubernetes; -import io.enmasse.systemtest.iot.DefaultDeviceRegistry; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.Quantity; - -@Tag(SMOKE) -@Kubernetes -class SimpleK8sDeployTest extends TestBase implements ITestIoTIsolated { - - private static final Logger log = LoggerFactory.getLogger(SimpleK8sDeployTest.class); - private static final String NAMESPACE = Environment.getInstance().namespace(); - private static IoTConfig config; - private io.enmasse.systemtest.platform.Kubernetes client = io.enmasse.systemtest.platform.Kubernetes.getInstance(); - - @BeforeAll - static void setup() throws Exception { - Map secrets = new HashMap<>(); - secrets.put("iot-auth-service", "systemtests-iot-auth-service-tls"); - secrets.put("iot-tenant-service", "systemtests-iot-tenant-service-tls"); - secrets.put("iot-device-connection", "systemtests-iot-device-connection-tls"); - secrets.put("iot-device-registry", "systemtests-iot-device-registry-tls"); - - var r1 = new ContainerConfigBuilder() - .withNewResources().addToLimits("memory", new Quantity("64Mi")).endResources() - .build(); - var j2 = new JavaContainerConfigBuilder() - .withNewContainerConfig() - .withNewResources().addToLimits("memory", new Quantity("256Mi")).endResources() - .endContainerConfig() - .build(); - - var commonContainers = new CommonAdapterContainersBuilder() - .withNewAdapterLike(j2).endAdapter() - .withNewProxyLike(r1).endProxy() - .withNewProxyConfiguratorLike(r1).endProxyConfigurator() - .build(); - - var jdbcEndpoint = SystemtestsKubernetesApps.deployPostgresqlServer(); - - config = IoTTestSession.createDefaultConfig() - - .editOrNewSpec() - - .editOrNewAdapters() - - .editOrNewHttp() - .withNewContainersLike(commonContainers).endContainers() - .endHttp() - - .editOrNewMqtt() - .withNewContainersLike(commonContainers).endContainers() - .endMqtt() - - .editOrNewSigfox() - .withNewContainersLike(commonContainers).endContainers() - .endSigfox() - - .editOrNewLoraWan() - .withNewContainersLike(commonContainers).endContainers() - .endLoraWan() - - .endAdapters() - - .withNewServices() - - .withNewAuthentication() - .withNewContainerLike(j2).endContainer() - .endAuthentication() - - .withNewTenant() - .withNewContainerLike(j2).endContainer() - .endTenant() - - .withDeviceConnection(DefaultDeviceRegistry.newPostgresBasedConnection(jdbcEndpoint)) - .withDeviceRegistry(DefaultDeviceRegistry.newPostgresBasedRegistry(jdbcEndpoint, false)) - - .editDeviceConnection() - .editJdbc() - .editOrNewCommonServiceConfig() - .withNewContainerLike(j2).endContainer() - .endCommonServiceConfig() - .endJdbc() - .endDeviceConnection() - - .editDeviceRegistry() - .editJdbc() - .editServer() - .editExternal() - .editManagement() - .editOrNewCommonConfig() - .withNewContainerLike(j2).endContainer() - .endCommonConfig() - .endManagement() - .endExternal() - .endServer() - .endJdbc() - .endDeviceRegistry() - - .endServices() - - .endSpec() - .build(); - - final Path configTempFile = Files.createTempFile("iot-config", "json"); - try { - Files.write(configTempFile, new ObjectMapper().writeValueAsBytes(config)); - KubeCMDClient.createFromFile(NAMESPACE, configTempFile); - } finally { - Files.deleteIfExists(configTempFile); - } - } - - @AfterAll - static void cleanup() throws Exception { - KubeCMDClient.deleteIoTConfig(NAMESPACE, "default"); - log.info("Waiting for IoT components to be removed"); - TestUtils.waitForNReplicas(0, NAMESPACE, singletonMap("component", "iot"), ofDuration(ofMinutes(5))); - } - - @Test - void testDeploy() throws Exception { - IoTUtils.waitForIoTConfigReady(client, config); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java deleted file mode 100644 index ee4098122a3..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/HttpAdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.http; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.DeviceSupplier.named; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; - -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; - -@Tag(ISOLATED_IOT) -class HttpAdapterTest implements StandardIoTHttpTests { - - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - session = IoTTestSession.createDefault() - .adapters(HTTP) - .deploy(); - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public List getDevices() { - return Arrays.asList( - named("default", () -> session.newDevice() - .register() - .setPassword())); - } - - @Override - public List getInvalidDevices() { - return Arrays.asList( - named("invalidPassword", () -> session.newDevice() - .register() - .setPassword() - .overridePassword())); - } - - @Override - public IoTTestSession getSession() { - return session; - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java deleted file mode 100644 index 7b57b6375fd..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/http/MaxPayloadSizeTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.http; - -import static io.enmasse.systemtest.iot.HttpAdapterClient.ResponseException.statusCode; - -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.isolated.AbstractMaxPayloadSizeTest; - -public class MaxPayloadSizeTest extends AbstractMaxPayloadSizeTest { - - @Override - protected Adapter adapter() { - return Adapter.HTTP; - } - - @SuppressWarnings("resource") - @Override - protected Sender sender(Device device) throws Exception { - return cleanup(device - .createHttpAdapterClient() - .suppressExceptions(statusCode(413)))::send; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java deleted file mode 100644 index 5acfc5fb908..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MaxPayloadSizeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.mqtt; - -import java.nio.charset.StandardCharsets; - -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester.Sender; -import io.enmasse.systemtest.iot.MessageSendTester.Type; -import io.enmasse.systemtest.iot.isolated.AbstractMaxPayloadSizeTest; - -public class MaxPayloadSizeTest extends AbstractMaxPayloadSizeTest { - - @Override - protected int reducePayloadBy(final Type type) { - // reduce by: 2 (length) + x (topic name) bytes + 2 (QoS 1 msg id) - return 2 + type.type().address().getBytes(StandardCharsets.UTF_8).length + 2; - } - - @Override - protected Adapter adapter() { - return Adapter.MQTT; - } - - @SuppressWarnings("resource") - @Override - protected Sender sender(Device device) throws Exception { - return cleanup(device.createMqttAdapterClient())::sendQos1; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java deleted file mode 100644 index 9cc2b8e715f..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/mqtt/MqttAdapterTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.mqtt; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.DeviceSupplier.named; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; - -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -/** - * Testing MQTT message transmission. - */ -@Tag(ISOLATED_IOT) -class MqttAdapterTest implements StandardIoTMqttTests { - - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - session = IoTTestSession.createDefault() - .adapters(MQTT) - .deploy(); - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public List getDevices() { - return Arrays.asList( - named("default", () -> session.newDevice() - .register() - .setPassword())); - } - - @Override - public List getInvalidDevices() { - return Arrays.asList( - named("invalidPassword", () -> session.newDevice() - .register() - .setPassword() - .overridePassword())); - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java deleted file mode 100644 index eade350eb0e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/project/ManagedTest.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated.project; - -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newDefaultInstance; -import static io.enmasse.systemtest.utils.AddressSpaceUtils.addressSpaceExists; -import static io.enmasse.systemtest.utils.TestUtils.waitUntilConditionOrFail; -import static java.time.Duration.ofMinutes; -import static java.time.Duration.ofSeconds; -import static org.hamcrest.collection.IsEmptyIterable.emptyIterable; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.net.HttpURLConnection; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; -import java.util.function.BiConsumer; - -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressList; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceList; -import io.enmasse.address.model.DoneableAddress; -import io.enmasse.address.model.DoneableAddressSpace; -import io.enmasse.address.model.KubeUtil; -import io.enmasse.iot.model.v1.DoneableIoTProject; -import io.enmasse.iot.model.v1.IoTConfig; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectBuilder; -import io.enmasse.iot.model.v1.IoTProjectList; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.Type; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.user.model.v1.DoneableUser; -import io.enmasse.user.model.v1.User; -import io.enmasse.user.model.v1.UserList; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.Resource; - -public class ManagedTest extends TestBase implements ITestIoTIsolated { - - private static final String MANAGED_TEST_ADDRESSSPACE = "managed-test-addrspace"; - - private static final Logger log = CustomLogger.getLogger(); - - private MixedOperation> client; - private MixedOperation> addressClient; - private MixedOperation> addressSpaceClient; - private MixedOperation> userClient; - protected DeviceRegistryClient registryClient; - protected CredentialsRegistryClient credentialsClient; - - private Endpoint httpAdapterEndpoint; - private UserCredentials credentials; - - @BeforeEach - public void initClients () throws Exception { - IoTConfig iotConfig = IoTTestSession.createDefaultConfig() - .editOrNewSpec().withServices(newDefaultInstance()).endSpec() - .build(); - - isolatedIoTManager.createIoTConfig(iotConfig); - - final Endpoint deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - this.registryClient = new DeviceRegistryClient(deviceRegistryEndpoint); - this.credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint); - this.client = kubernetes.getIoTProjectClient(IOT_PROJECT_NAMESPACE); - this.addressClient = kubernetes.getAddressClient(IOT_PROJECT_NAMESPACE); - this.addressSpaceClient = kubernetes.getAddressSpaceClient(IOT_PROJECT_NAMESPACE); - this.userClient = kubernetes.getUserClient(IOT_PROJECT_NAMESPACE); - this.httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - - this.credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - } - - @Test - public void testChangeAddressSpace() throws Exception { - - var project = IoTUtils.getBasicIoTProjectObject("iot1", "as1", - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(project); - - assertManagedResources(Assertions::assertNotNull, project, "as1"); - - project = new IoTProjectBuilder(project) - .editSpec() - .editDownstreamStrategy() - .editManagedStrategy() - .editAddressSpace() - - .withName("as1a") - - .endAddressSpace() - .endManagedStrategy() - .endDownstreamStrategy() - .endSpec() - .build(); - - // update the project - - log.info("Update project namespace"); - client.createOrReplace(project); - - // immediately after the change, the project is still ready but the new - // address space is still missing, so we need to wait for it to be created - // otherwise io.enmasse.systemtest.utils.IoTUtils.waitForIoTProjectReady(Kubernetes, IoTProject) will fail - - waitUntilConditionOrFail( - addressSpaceExists(project.getMetadata().getNamespace(), project.getSpec().getDownstreamStrategy().getManagedStrategy().getAddressSpace().getName()), - ofMinutes(5), ofSeconds(10), - () -> String.format("Expected address space to be created")); - - // wait until the project and address space become ready - - log.info("For for project to become ready again"); - IoTUtils.waitForIoTProjectReady(kubernetes, project); - - // assert existence - - assertManagedResources(Assertions::assertNotNull, project, "as1a"); - assertManagedResources(Assertions::assertNull, project, "as1"); - } - - @Test - public void testTwoManagedToTheSameAddressSpace() throws Exception { - - // first create two projects for a single address space - - var project1 = IoTUtils.getBasicIoTProjectObject("iot1", MANAGED_TEST_ADDRESSSPACE, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - var project2 = IoTUtils.getBasicIoTProjectObject("iot2", MANAGED_TEST_ADDRESSSPACE, - IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - - var tenant1 = IoTUtils.getTenantId(project1); - var tenant2 = IoTUtils.getTenantId(project2); - - // wait for the projects to be ready - - isolatedIoTManager.createIoTProject(project1); - isolatedIoTManager.createIoTProject(project2); - - assertManagedResources(Assertions::assertNotNull, project1, MANAGED_TEST_ADDRESSSPACE); - assertManagedResources(Assertions::assertNotNull, project2, MANAGED_TEST_ADDRESSSPACE); - - // register two devices with the same ids, but for different tenants - - this.registryClient.registerDevice(tenant1, "device1"); - this.registryClient.registerDevice(tenant2, "device1"); - this.credentialsClient.addPlainPasswordCredentials(tenant1, "device1", "auth1", "password1", null, HttpURLConnection.HTTP_NO_CONTENT); - this.credentialsClient.addPlainPasswordCredentials(tenant2, "device1", "auth1", "password1", null, HttpURLConnection.HTTP_NO_CONTENT); - - // set up client - - isolatedIoTManager.createOrUpdateUser(isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, MANAGED_TEST_ADDRESSSPACE), this.credentials); - var iotAmqpClientFactory = new AmqpClientFactory(this.resourcesManager.getAddressSpace(IOT_PROJECT_NAMESPACE, MANAGED_TEST_ADDRESSSPACE), this.credentials); - var amqpClient = iotAmqpClientFactory.createQueueClient(); - - // now try to send some messages - - final List otherMessages = new LinkedList<>(); - try ( - var httpAdapterClient = new HttpAdapterClient(this.httpAdapterEndpoint, "auth1", tenant1, "password1"); - var otherReceiver = MessageSendTester.ConsumerFactory.of(amqpClient, tenant2).start(Type.TELEMETRY, msg -> otherMessages.add(msg)) ) { - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .amount(1) - .consumerFactory(MessageSendTester.ConsumerFactory.of(amqpClient, tenant1)) - .sender(httpAdapterClient::send) - .execute(); - - } - - assertThat(otherMessages, emptyIterable()); - } - - private void assertManagedResources(final BiConsumer assertor, final IoTProject project, final String addressSpaceName) { - assertObject(assertor, "Address space", this.addressSpaceClient, addressSpaceName); - assertObject(assertor, "Adapter user", this.userClient, addressSpaceName + ".adapter-" + project.getMetadata().getUid()); - for ( final String address : IOT_ADDRESSES) { - var addressName = address + "/" + IOT_PROJECT_NAMESPACE + "." + project.getMetadata().getName(); - var metaName = KubeUtil.sanitizeForGo(addressSpaceName, addressName); - assertObject(assertor, "Address: " + addressName + " / " + metaName, this.addressClient, metaName); - } - } - - private static void assertObject(final BiConsumer assertor, final String message, final MixedOperation client, final String name) { - var object = client.withName(name).get(); - assertor.accept(object, message); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java deleted file mode 100644 index fd709d39543..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/DeviceRegistryTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.SMOKE; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static java.net.HttpURLConnection.HTTP_CONFLICT; -import static java.net.HttpURLConnection.HTTP_CREATED; -import static java.net.HttpURLConnection.HTTP_NOT_FOUND; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.net.HttpURLConnection; -import java.nio.charset.StandardCharsets; -import java.time.Duration; -import java.time.Instant; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import org.eclipse.hono.service.management.credentials.CommonCredential; -import org.eclipse.hono.service.management.credentials.PasswordCredential; -import org.eclipse.hono.service.management.device.Device; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.amqp.AmqpClientFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.utils.IoTUtils; - -@Tag(SMOKE) -abstract class DeviceRegistryTest extends TestBase implements ITestIoTIsolated { - - private static final String DEVICE_REGISTRY_TEST_ADDRESSSPACE = "device-registry-test-addrspace"; - - private static final String DEVICE_REGISTRY_TEST_PROJECT = "device-registry-test-project"; - - private String randomDeviceId; - private IoTProject iotProject; - private Endpoint deviceRegistryEndpoint; - private Endpoint httpAdapterEndpoint; - private DeviceRegistryClient client; - - private UserCredentials credentials; - - private AmqpClientFactory iotAmqpClientFactory; - - private AmqpClient amqpClient; - - protected abstract IoTConfigBuilder provideIoTConfig() throws Exception; - - protected int tenantDoesNotExistCode() { - return HttpURLConnection.HTTP_UNAUTHORIZED; - } - - @BeforeEach - public void setAttributes() throws Exception { - var iotConfigBuilder = provideIoTConfig(); - - // disable all but HTTP - - for (Adapter adapter : Adapter.values()) { - iotConfigBuilder = adapter.disable(iotConfigBuilder); - } - iotConfigBuilder = HTTP.enable(iotConfigBuilder); - - // build config - - var iotConfig = iotConfigBuilder.build(); - - isolatedIoTManager.createIoTConfig(iotConfig); - - iotProject = IoTUtils.getBasicIoTProjectObject(DEVICE_REGISTRY_TEST_PROJECT, - DEVICE_REGISTRY_TEST_ADDRESSSPACE, IOT_PROJECT_NAMESPACE, getDefaultAddressSpacePlan()); - isolatedIoTManager.createIoTProject(iotProject); - - deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - - httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - - client = new DeviceRegistryClient(deviceRegistryEndpoint); - - this.randomDeviceId = UUID.randomUUID().toString(); - - this.credentials = new UserCredentials(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - isolatedIoTManager.createOrUpdateUser(isolatedIoTManager.getAddressSpace(IOT_PROJECT_NAMESPACE, DEVICE_REGISTRY_TEST_ADDRESSSPACE), this.credentials); - this.iotAmqpClientFactory = new AmqpClientFactory(resourcesManager.getAddressSpace(IOT_PROJECT_NAMESPACE, DEVICE_REGISTRY_TEST_ADDRESSSPACE), this.credentials); - this.amqpClient = iotAmqpClientFactory.createQueueClient(); - - } - - protected void doTestRegisterDevice() throws Exception { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - assertNotNull(result); - assertDefaultEnabled(result.isEnabled()); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - - protected void doTestDisableDevice() throws Exception { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final Device payload = new Device(); - payload.setEnabled(false); - - client.updateDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, payload); - - final Device result = client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - - // as we set it explicitly, we expect the explicit value of "false" - assertEquals(Boolean.FALSE, result.isEnabled()); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - - protected void doTestDeviceCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - protected void doTestDeviceCredentialsPlainPassword() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addPlainPasswordCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - protected void doTestDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - String authId = "sensor-" + UUID.randomUUID().toString(); - String password = "password1234"; - credentialsClient.addPlainPasswordCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - List credentials = credentialsClient.getCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - assertEquals(1, credentials.size()); - PasswordCredential passwordCredential = ((PasswordCredential) credentials.get(0)); - assertEquals(1, passwordCredential.getSecrets().size()); - assertNull(passwordCredential.getSecrets().get(0).getHashFunction()); - assertNull(passwordCredential.getSecrets().get(0).getPasswordHash()); - assertNull(passwordCredential.getSecrets().get(0).getPasswordPlain()); - assertNull(passwordCredential.getSecrets().get(0).getSalt()); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - - } - } - - - protected void doTestCacheExpiryForCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - - final Duration cacheExpiration = Duration.ofMinutes(3); - - // register device - - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final String password = "password1234"; - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, password, null, HttpURLConnection.HTTP_NO_CONTENT); - - // first test, cache filled - - IoTUtils.checkCredentials(authId, password, false, httpAdapterEndpoint, amqpClient, iotProject); - - // set new password - - final String newPassword = "new-password1234"; - credentialsClient.updateCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, newPassword, null); - - // expect failure due to cached info - - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - LOGGER.info("Waiting {} seconds for credentials to expire", cacheExpiration); - Thread.sleep(cacheExpiration.toMillis()); - - // cache must be expired, new password can be used - - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - } - - - protected void doTestSetExpiryForCredentials() throws Exception { - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - client.registerDevice(isolatedIoTManager.getTenantId(), randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final Duration expiry = Duration.ofSeconds(30); - final Instant notAfter = Instant.now().plus(expiry); - final String newPassword = "password1234"; - - credentialsClient.addCredentials(isolatedIoTManager.getTenantId(), randomDeviceId, authId, newPassword, notAfter, HttpURLConnection.HTTP_NO_CONTENT); - - // first check, must succeed - Thread.sleep(20_000); - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - LOGGER.info("Waiting {} for credentials to expire", expiry); - Thread.sleep(expiry.toMillis()); - - // second check, after expiration, must fail - - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - - credentialsClient.deleteAllCredentials(isolatedIoTManager.getTenantId(), randomDeviceId); - - client.deleteDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId); - client.getDeviceRegistration(isolatedIoTManager.getTenantId(), randomDeviceId, HTTP_NOT_FOUND); - } - } - - - protected void doTestCreateForNonExistingTenantFails() throws Exception { - var response = client.registerDeviceWithResponse("invalid-" + isolatedIoTManager.getTenantId(), randomDeviceId); - assertEquals(tenantDoesNotExistCode(), response.statusCode()); - } - - protected void doTestTenantDeletionTriggersDevicesDeletion() throws Exception { - var tenantId = isolatedIoTManager.getTenantId(); - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - client.registerDevice(tenantId, randomDeviceId); - - final String authId = UUID.randomUUID().toString(); - final Duration expiry = Duration.ofSeconds(30); - final Instant notAfter = Instant.now().plus(expiry); - final String newPassword = "password1234"; - - credentialsClient.addCredentials(tenantId, randomDeviceId, authId, newPassword, notAfter, HttpURLConnection.HTTP_NO_CONTENT); - - // first check, must succeed - - IoTUtils.checkCredentials(authId, newPassword, false, httpAdapterEndpoint, amqpClient, iotProject); - - // Now delete the tenant - isolatedIoTManager.deleteIoTProject(iotProject); - - // second check, the credentials and device should be deleted - - client.getDeviceRegistration(tenantId, randomDeviceId, tenantDoesNotExistCode()); - IoTUtils.checkCredentials(authId, newPassword, true, httpAdapterEndpoint, amqpClient, iotProject); - } - } - - protected void doCreateDuplicateDeviceFails() throws Exception { - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId = UUID.randomUUID().toString(); - - // create device - - var response = client.registerDeviceWithResponse(tenantId, deviceId); - assertEquals(HTTP_CREATED, response.statusCode()); - - // create device a second time - - var response2 = client.registerDeviceWithResponse(tenantId, deviceId); - assertEquals(HTTP_CONFLICT, response2.statusCode()); - } - - @Test - public void testDeviceWithSameAuthIdOfDifferentTypesSucceeds() throws Exception { - - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId = UUID.randomUUID().toString(); - - // create device - - client.registerDevice(tenantId, deviceId); - - var authId = UUID.randomUUID().toString(); - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId, authId, "foo-bar", null, HttpURLConnection.HTTP_NO_CONTENT); - credentialsClient.addPskCredentials(tenantId, deviceId, authId, "foo-bar".getBytes(StandardCharsets.UTF_8), null, HttpURLConnection.HTTP_NO_CONTENT); - } - - } - - @Test - public void testDeviceWithSameAuthIdOfSameTypesFails() throws Exception { - - var tenantId = isolatedIoTManager.getTenantId(); - var deviceId1 = UUID.randomUUID().toString(); - var deviceId2 = UUID.randomUUID().toString(); - - // create device - - client.registerDevice(tenantId, deviceId1); - client.registerDevice(tenantId, deviceId2); - - var authId = UUID.randomUUID().toString(); - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - // must succeed - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId1, authId, "foo-bar", null, HttpURLConnection.HTTP_NO_CONTENT); - // must fail - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId2, authId, "foo-bar", null, HttpURLConnection.HTTP_BAD_REQUEST); - } - - } - - protected void doRegisterMultipleDevices() throws Exception { - - final String tenantId = isolatedIoTManager.getTenantId(); - final String prefix = UUID.randomUUID().toString(); - final Set devices = new HashSet<>(); - - for (int i = 0; i < 1_000; i++) { - var deviceId = prefix + "-" + UUID.randomUUID().toString(); - client.registerDevice(tenantId, deviceId); - devices.add(deviceId); - } - - try (var credentialsClient = new CredentialsRegistryClient(deviceRegistryEndpoint)) { - for (final String deviceId : devices) { - credentialsClient.addPlainPasswordCredentials(tenantId, deviceId, UUID.randomUUID().toString(), UUID.randomUUID().toString(), null, HttpURLConnection.HTTP_NO_CONTENT); - } - } - - for (final String deviceId : devices) { - final Device result = client.getDeviceRegistration(tenantId, deviceId); - assertNotNull(result); - assertDefaultEnabled(result.isEnabled()); - } - - for (final String deviceId : devices) { - client.deleteDeviceRegistration(tenantId, deviceId); - } - - for (final String deviceId : devices) { - client.getDeviceRegistration(tenantId, deviceId, HTTP_NOT_FOUND); - } - - } - -} \ No newline at end of file diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java deleted file mode 100644 index e1552f0288e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/H2DeviceRegistryTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newH2Based; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; - -class H2DeviceRegistryTest extends DeviceRegistryTest { - - private final Logger log = CustomLogger.getLogger(); - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newH2Based()) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("jdbc"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - - // dump content, just in case - - dumpH2Database(); - - // ensure that the database is still present, but has zero entries - - final List command = new ArrayList<>(Arrays.asList(SystemtestsKubernetesApps.H2_SHELL_COMMAND)); - command.addAll(Arrays.asList("-sql", "select count(*) as NUM from device_registrations")); - - var pod = SystemtestsKubernetesApps - .getH2ServerPod() - .orElseThrow(() -> new IllegalStateException("Unable to find H2 server pod")); - final String[] result = Kubernetes.executeWithInput(pod, null, null, Duration.ofSeconds(10), - command.toArray(String[]::new) - ) - .split("[\r\n]+"); - - // must have three lines - assertEquals(3, result.length); - // first: the column name - assertEquals("NUM", result[0]); - // second: the number of entries, which must be zero - assertEquals("0", result[1]); - // third: the execution statistics, which we ignore - - } - - private void dumpH2Database() throws IOException, InterruptedException, TimeoutException { - final List command = new ArrayList<>(Arrays.asList(SystemtestsKubernetesApps.H2_SHELL_COMMAND)); - command.addAll(Arrays.asList("-sql", "select * from device_registrations")); - - var pod = SystemtestsKubernetesApps - .getH2ServerPod() - .orElseThrow(() -> new IllegalStateException("Unable to find H2 server pod")); - final String result = Kubernetes.executeWithInput(pod, null, null, Duration.ofSeconds(10), - command.toArray(String[]::new)); - - log.info("Current H2 database:\n{}", result); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java deleted file mode 100644 index c510e7ed00c..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/InfinispanDeviceRegistryTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newInfinispanBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import java.net.HttpURLConnection; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -class InfinispanDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected int tenantDoesNotExistCode() { - return HttpURLConnection.HTTP_UNAUTHORIZED; - } - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newInfinispanBased()) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("infinispan"); - assertCorrectRegistryType("infinispan"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } - - @Override - @Disabled("Not supported by Infinispan") - public void testDeviceWithSameAuthIdOfSameTypesFails() throws Exception { - super.testDeviceWithSameAuthIdOfSameTypesFails(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java deleted file mode 100644 index a69acad66cf..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/MixedDeviceRegistryTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBasedRegistry; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.DefaultDeviceRegistry; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; - -class MixedDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - - var jdbcEndpoint = SystemtestsKubernetesApps.deployPostgresqlServer(); - var infinispanEndpoint = SystemtestsKubernetesApps.deployInfinispanServer(); - - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withNewServices() - .withDeviceConnection(DefaultDeviceRegistry.newInfinispanDeviceConnectionService(infinispanEndpoint)) - .withDeviceRegistry(newPostgresBasedRegistry(jdbcEndpoint, false)) - .endServices() - .endSpec(); - - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("infinispan"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java deleted file mode 100644 index f0491ad3aef..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableDeviceRegistryTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectDeviceConnectionType; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -class PostgresTableDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newPostgresBased(false)) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectDeviceConnectionType("jdbc"); - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java deleted file mode 100644 index 307a9a085e9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/registry/PostgresTableSplitDeviceRegistryTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2019-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.registry; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.DefaultDeviceRegistry.newPostgresBased; -import static io.enmasse.systemtest.utils.IoTUtils.assertCorrectRegistryType; - -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.iot.model.v1.IoTConfigBuilder; -import io.enmasse.systemtest.iot.IoTTestSession; - -/** - * Postgres table model, split adapter and management pods. - */ -class PostgresTableSplitDeviceRegistryTest extends DeviceRegistryTest { - - @Override - protected IoTConfigBuilder provideIoTConfig() throws Exception { - return IoTTestSession - .createDefaultConfig() - .editOrNewSpec() - .withServices(newPostgresBased(true)) - .endSpec(); - } - - @Test - void testCorrectTypeDeployed () { - assertCorrectRegistryType("jdbc"); - } - - @Test - @Tag(ACCEPTANCE) - void testRegisterDevice() throws Exception { - super.doTestRegisterDevice(); - } - - @Test - @Tag(ACCEPTANCE) - void testDisableDevice() throws Exception { - super.doTestDisableDevice(); - } - - @Test - void testDeviceCredentials() throws Exception { - super.doTestDeviceCredentials(); - } - - @Test - void testDeviceCredentialsPlainPassword() throws Exception { - super.doTestDeviceCredentialsPlainPassword(); - } - - @Test - @Disabled("Fixed in hono/pull/1565") - void testDeviceCredentialsDoesNotContainsPasswordDetails() throws Exception { - super.doTestDeviceCredentialsDoesNotContainsPasswordDetails(); - } - - @Test - @Disabled("Caches expire a bit unpredictably") - void testCacheExpiryForCredentials() throws Exception { - super.doTestCacheExpiryForCredentials(); - } - - @Test - void testSetExpiryForCredentials() throws Exception { - super.doTestSetExpiryForCredentials(); - } - - @Test - void testCreateForNonExistingTenantFails() throws Exception { - super.doTestCreateForNonExistingTenantFails(); - } - - @Test - void testCreateDuplicateDeviceFails() throws Exception { - super.doCreateDuplicateDeviceFails(); - } - - @Test - void testRegisterMultipleDevices() throws Exception { - super.doRegisterMultipleDevices(); - } - - @Test - void testTenantDeletionTriggersDevicesDeletion() throws Exception { - super.doTestTenantDeletionTriggersDevicesDeletion(); - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java deleted file mode 100644 index 0e06318f3f9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/ReloadCertificatesTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.tls; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static io.enmasse.systemtest.condition.OpenShiftVersion.OCP4; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.time.TimeoutBudget.ofDuration; -import static java.time.Duration.ofMinutes; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.time.Duration; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTIsolated; -import io.enmasse.systemtest.condition.OpenShift; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Device; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.client.KubernetesClient; - -@Tag(ISOLATED) -public class ReloadCertificatesTest extends TestBase implements ITestIoTIsolated { - - private static final String NAMESPACE = Kubernetes.getInstance().getInfraNamespace(); - - private KubernetesClient client = Kubernetes.getInstance().getClient(); - - @Test - @OpenShift(version = OCP4) - public void testRecreateCertificate() throws Exception { - - IoTTestSession - .createDefault() - .adapters(HTTP) - .config(config -> { - // ensure we are using the service-ca - config.editOrNewSpec() - .withNewInterServiceCertificates() - .withNewServiceCAStrategy() - .endServiceCAStrategy() - .endInterServiceCertificates() - - .editOrNewAdapters() - .editOrNewHttp() - // reset to use service CA endpoint secret - .withNewEndpoint().endEndpoint() - .endHttp() - .endAdapters() - - .endSpec(); - }) - .run((session) -> { - - var deviceId = UUID.randomUUID().toString(); - var authId = UUID.randomUUID().toString(); - var password = UUID.randomUUID().toString(); - var device = session.newDevice(deviceId) - .register() - .setPassword(authId, password); - - // ensure everything works before starting - - assertTelemetryWorks(session, device); - - // get current pod - - var deploymentAccess = this.client - .apps().deployments() - .inNamespace(NAMESPACE) - .withName("iot-http-adapter"); - - var pod = this.client - .pods() - .inNamespace(NAMESPACE).withLabels(Map.of( - "app", "enmasse", - "name", "iot-http-adapter")) - .list().getItems().stream() - .map(p -> p.getMetadata().getName()) - .findFirst() - .orElse(null); - - assertNotNull(pod); - - // then: reset http adapter key/cert - - var deleteResult = this.client.secrets() - .inNamespace(NAMESPACE) - .withName("iot-http-adapter-tls") - .delete(); - - assertEquals(Boolean.TRUE, deleteResult); - - final TimeoutBudget budget = ofDuration(ofMinutes(10)); - - // wait until the deployment has changed - - var initialVersion = deploymentAccess.get().getMetadata().getResourceVersion(); - TestUtils.waitForChangedResourceVersion(budget, initialVersion, () -> { - return Optional.ofNullable(deploymentAccess.get()) - .map(d -> d.getMetadata().getResourceVersion()) - .orElse(initialVersion); - }); - - // and wait until the IoTConfig is ready again - - IoTUtils.waitForIoTConfigReady(Kubernetes.getInstance(), session.getConfig()); - - // now try to send messages again - - assertTelemetryWorks(session, device); - - }); - - } - - protected void assertTelemetryWorks(final IoTTestSession session, final Device device) throws Exception { - try (var adapterClient = device.createHttpAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofMillis(500)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(adapterClient::send) - .amount(30) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java deleted file mode 100644 index e75bf753189..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/tls/TlsVersionTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.tls; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static java.util.Collections.singleton; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import io.enmasse.systemtest.condition.OpenShift; -import io.enmasse.systemtest.condition.OpenShiftVersion; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTestSession.Adapter; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; - -@Tag(ISOLATED) -public class TlsVersionTest { - - @OpenShift(version = OpenShiftVersion.OCP4) - @Test - public void testWithExplicitVersion() throws Exception { - IoTTestSession - .createDefault() - .adapters(Adapter.HTTP) - .config(config -> config - .editOrNewSpec() - .editOrNewTls() - .withVersions("TLSv1.3") - .endTls() - .endSpec()) - .run(session -> { - - var device = session.registerNewRandomDeviceWithPassword(); - - try (HttpAdapterClient client = device.createHttpAdapterClient(singleton("TLSv1.3"))) { - - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - - } - - try (HttpAdapterClient client = device.createHttpAdapterClient(singleton("TLSv1.2"))) { - - // this must fail, as we offer TLSv1.2, but have only 1.3 configured - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(session.getConsumerClient(), session.getTenantId())) - .sender(client::send) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - - } - - }); - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java deleted file mode 100644 index 0afb7cdc95e..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/StandardX509Cases.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.iot.DeviceSupplier.named; - -import java.time.Duration; -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import javax.security.auth.x500.X500Principal; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.StandardIoTTests; - -public interface StandardX509Cases extends StandardIoTTests { - - DeviceCertificateManager getCertificateManager(); - - @Override - default List getDevices() { - - return Arrays.asList( - named("default", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager().createDevice()))); - - } - - @Override - default List getInvalidDevices() { - - return Arrays.asList( - notOurCaDevice(), - expiredCertificate(), - futureCertificate()); - - } - - /** - * Create a device which has a certificate signed by a CA with the same name, but which actually is - * not the same CA. - */ - default DeviceSupplier notOurCaDevice() { - - return named("notOurCa", () -> { - var otherMgr = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - return getSession().newDevice() - .register() - .enableX509(otherMgr.createDevice()); - }); - - } - - /** - * Create a device which has an expired certificate. - */ - default DeviceSupplier expiredCertificate() { - - final Instant now = Instant.now(); - - return named("expiredCertificate", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager() - .createDevice( - UUID.randomUUID().toString(), - now.minus(Duration.ofDays(30)), - now))); - - } - - /** - * Create a device which has an valid date in the future. - */ - default DeviceSupplier futureCertificate() { - - final Instant now = Instant.now(); - - return named("futureCertificate", () -> getSession().newDevice() - .register() - .enableX509(getCertificateManager() - .createDevice( - UUID.randomUUID().toString(), - now.plus(Duration.ofDays(100)), - now.plus(Duration.ofDays(200))))); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java deleted file mode 100644 index 4d287b288b3..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/TrustAnchorTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import java.time.Duration; -import java.util.Optional; -import java.util.UUID; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.enmasse.iot.model.v1.IoTProject; -import io.enmasse.iot.model.v1.IoTProjectBuilder; -import io.enmasse.iot.model.v1.IoTProjectStatus; -import io.enmasse.iot.model.v1.ProjectConditionType; -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.IoTTests; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; - -@Tag(ISOLATED_IOT) -public class TrustAnchorTests implements IoTTests { - - private static final Logger log = LoggerFactory.getLogger(TrustAnchorTests.class); - - /** - * Test creating duplicate "subject dn". - */ - @Test - @Tag(ACCEPTANCE) - public void testDuplicateSubjectDn() throws Exception { - var mgr1 = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - var mgr2 = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - final String name2 = UUID.randomUUID().toString(); - final String ns2 = UUID.randomUUID().toString(); - Kubernetes.getInstance().createNamespace(ns2); - - try (IoTTestSession session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(mgr1.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(HTTP) - .deploy()) { - - // now create a second project, in second namespace, with a new CA - // having the same name. This must fail. - - var project2 = new IoTProjectBuilder(IoTUtils.getBasicIoTProjectObject( - name2, name2, ns2, - AddressSpacePlans.STANDARD_SMALL)) - - .editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(mgr2.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec() - - .build(); - - // create - - var projectClient = Kubernetes.getInstance().getIoTProjectClient(ns2); - session.addCleanup(() -> IoTUtils.deleteIoTProjectAndWait(project2)); - projectClient.create(project2); - var projectAccess = projectClient.withName(name2); - - // and wait for the condition - - TestUtils.waitUntilConditionOrFail(() -> { - - // wait until the condition 'TrustAnchorsUnique' becomes false - return Optional - .ofNullable(projectAccess.get()) - .map(IoTProject::getStatus) - .map(IoTProjectStatus::getConditions) - .flatMap(c -> c.stream() - .filter(condition -> condition.getType() == ProjectConditionType.TRUST_ANCHORS_UNIQUE) - .findAny()) - .map(c -> "false".equalsIgnoreCase(c.getStatus()) && - "DuplicateTrustAnchors".equals(c.getReason())) - .orElse(false); - - }, Duration.ofMinutes(5), Duration.ofSeconds(10), () -> "Conditions 'TrustAnchorsUnique' should become 'false'"); - - log.info("Successfully detected 'DuplicateTrustAnchors' problem on second project"); - - } - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java deleted file mode 100644 index bdfa0237ceb..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509EcAuthenticationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -@Tag(ISOLATED_IOT) -public class X509EcAuthenticationTests implements StandardX509Cases, StandardIoTHttpTests, StandardIoTMqttTests { - - private static DeviceCertificateManager certificateManager; - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - - certificateManager = new DeviceCertificateManager(Mode.EC, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(certificateManager.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(MQTT, HTTP) - .deploy(); - - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public DeviceCertificateManager getCertificateManager() { - return certificateManager; - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java deleted file mode 100644 index 7b3540767c1..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/isolated/x509/X509RsaAuthenticationTests.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.isolated.x509; - -import static io.enmasse.systemtest.TestTag.ISOLATED_IOT; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.HTTP; -import static io.enmasse.systemtest.iot.IoTTestSession.Adapter.MQTT; -import static io.enmasse.systemtest.utils.TestUtils.toPem; - -import javax.security.auth.x500.X500Principal; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Tag; - -import io.enmasse.systemtest.iot.DeviceCertificateManager; -import io.enmasse.systemtest.iot.DeviceCertificateManager.Mode; -import io.enmasse.systemtest.iot.IoTTestSession; -import io.enmasse.systemtest.iot.http.StandardIoTHttpTests; -import io.enmasse.systemtest.iot.mqtt.StandardIoTMqttTests; - -@Tag(ISOLATED_IOT) -public class X509RsaAuthenticationTests implements StandardX509Cases, StandardIoTHttpTests, StandardIoTMqttTests { - - private static DeviceCertificateManager certificateManager; - private static IoTTestSession session; - - @BeforeAll - public static void setup() throws Exception { - - certificateManager = new DeviceCertificateManager(Mode.RSA, new X500Principal("OU=Tenant 1,OU=IoT,O=EnMasse,C=IO")); - - session = IoTTestSession.createDefault() - .project(project -> project.editOrNewSpec() - .editOrNewConfiguration() - .addNewTrustAnchor() - .withCertificate(toPem(certificateManager.getCertificate())) - .endTrustAnchor() - .endConfiguration() - .endSpec()) - .adapters(MQTT, HTTP) - .deploy(); - - } - - @AfterAll - public static void cleanup() throws Exception { - if (session != null) { - session.close(); - session = null; - } - } - - @Override - public DeviceCertificateManager getCertificateManager() { - return certificateManager; - } - - @Override - public IoTTestSession getSession() { - return session; - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java deleted file mode 100644 index dcf43f5bba6..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/mqtt/StandardIoTMqttTests.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright 2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ - -package io.enmasse.systemtest.iot.mqtt; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.fail; - -import java.time.Duration; -import java.util.concurrent.TimeoutException; - -import javax.net.ssl.SSLHandshakeException; - -import org.eclipse.paho.client.mqttv3.MqttSecurityException; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.Throwables; - -import io.enmasse.systemtest.iot.DeviceSupplier; -import io.enmasse.systemtest.iot.MessageSendTester; -import io.enmasse.systemtest.iot.MessageSendTester.ConsumerFactory; -import io.enmasse.systemtest.iot.MqttAdapterClient; -import io.enmasse.systemtest.iot.StandardIoTTests; - -/** - * Standard MQTT IoT tests - *

- * Note: we do not test single telemetry with QoS 0 here, as we don't receive any - * feedback if the message was accepted or not. So we couldn't re-try and could only assume that a - * message loss of 100% would be acceptable, which doesn't test much. For bigger batch sizes we can - * test with an acceptable message loss rate of e.g. 10%. - */ -public interface StandardIoTMqttTests extends StandardIoTTests { - - final static Logger log = LoggerFactory.getLogger(StandardIoTMqttTests.class); - - /** - * Single telemetry message with attached consumer. QoS 1. - *
- * Sending with QoS 1 is ok. - */ - @Tag(ACCEPTANCE) - @ParameterizedTest(name = "testMqttTelemetrySingleQos1-{0}") - @MethodSource("getDevices") - default void testMqttTelemetrySingleQos1(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(1) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Single event message with non-attached consumer. - *
- * This is the normal use case. - */ - @ParameterizedTest(name = "testMqttEventSingle-{0}") - @MethodSource("getDevices") - default void testMqttEventSingle(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(1) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Batch of telemetry messages with attached consumer. QoS 0. - *
- * Batched version of the normal use case. We do accept message loss of 10% here. - */ - @ParameterizedTest(name = "testMqttTelemetryBatch50Qos0-{0}") - @MethodSource("getDevices") - default void testMqttTelemetryBatch50Qos0(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos0) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .acceptableMessageLoss(5) // allow for 10% - .execute(); - } - - } - - /** - * Batch of telemetry messages with attached consumer. QoS 1. - *
- * Compared to QoS 0, we do not accept message loss here. - */ - @ParameterizedTest(name = "testMqttTelemetryBatch50Qos1-{0}") - @MethodSource("getDevices") - default void testMqttTelemetryBatch50Qos1(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(50) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Batch of event messages with non-attached consumer. - *
- * This sends messages without an attached consumer. The broker is expected - * to take care of that. Still we expect to receive the messages later. - */ - @ParameterizedTest(name = "testMqttEventBatch5After-{0}") - @MethodSource("getDevices") - default void testMqttEventBatch5After(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofMillis(100)) - .additionalSendTimeout(Duration.ofSeconds(2)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.AFTER) - .execute(); - } - - } - - /** - * Batch of event messages with attached consumer. - *
- * This is the normal use case. - */ - @ParameterizedTest(name = "testMqttEventBatch5Before-{0}") - @MethodSource("getDevices") - default void testMqttEventBatch5Before(final DeviceSupplier device) throws Exception { - - try (MqttAdapterClient client = device.get().createMqttAdapterClient()) { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - } - - } - - /** - * Test for an invalid device. - *
- * With an invalid device, no messages must pass. - */ - @ParameterizedTest(name = "testMqttInvalidDevice-{0}") - @MethodSource("getInvalidDevices") - default void testMqttInvalidDevice(final DeviceSupplier deviceSupplier) throws Exception { - - log.info("Testing invalid devices, the following exception may be expected"); - - // get the device now, once, throwing out of the test method - - var device = deviceSupplier.get(); - - /* - * We test an invalid device by trying to send either telemetry or event messages. - * Two separate connections, and more than one message. - * - * We do expect a failure, but it must be a specific failure. We do accept - * an MqttSecurityException when opening the connection, or a TimeoutException - * when we could open the connection, but not send/receive. - */ - - try (MqttAdapterClient client = device.createMqttAdapterClient()) { - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.TELEMETRY) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } catch (Exception e) { - assertConnectionException(e); - log.debug("Accepting MQTT exception", e); - } - - try (MqttAdapterClient client = device.createMqttAdapterClient()) { - assertThrows(TimeoutException.class, () -> { - new MessageSendTester() - .type(MessageSendTester.Type.EVENT) - .delay(Duration.ofSeconds(1)) - .consumerFactory(ConsumerFactory.of(getSession().getConsumerClient(), getSession().getTenantId())) - .sender(client::sendQos1) - .amount(5) - .consume(MessageSendTester.Consume.BEFORE) - .execute(); - }); - } catch (Exception e) { - assertConnectionException(e); - log.debug("Accepting MQTT exception", e); - } - - } - - public static void assertConnectionException(final Throwable e) { - - // if we get an exception, it must be an MqttSecurityException or SSLHandshakeException - - if (e instanceof MqttSecurityException) { - return; - } - - final Throwable cause = Throwables.getRootCause(e); - if (cause instanceof SSLHandshakeException) { - return; - } - - fail("Failed to connect with non-permitted exception", e); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java b/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java deleted file mode 100644 index 8a16e5bd431..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/iot/shared/control/CommandAndControlTest.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright 2019, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.iot.shared.control; - -import static io.enmasse.systemtest.TestTag.ACCEPTANCE; -import static io.enmasse.systemtest.iot.MessageType.COMMAND_RESPONSE; -import static io.enmasse.systemtest.iot.MessageType.TELEMETRY; -import static io.enmasse.systemtest.utils.Predicates.is; -import static java.net.HttpURLConnection.HTTP_ACCEPTED; -import static java.net.HttpURLConnection.HTTP_OK; -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.hamcrest.core.IsNull.notNullValue; -import static org.hamcrest.MatcherAssert.assertThat; - -import java.net.HttpURLConnection; -import java.nio.ByteBuffer; -import java.time.Duration; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.Accepted; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.messaging.Released; -import org.apache.qpid.proton.message.Message; -import org.hamcrest.core.Is; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; - -import io.enmasse.systemtest.Endpoint; -import io.enmasse.systemtest.amqp.QueueTerminusFactory; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.iot.ITestIoTShared; -import io.enmasse.systemtest.iot.CredentialsRegistryClient; -import io.enmasse.systemtest.iot.DeviceRegistryClient; -import io.enmasse.systemtest.iot.HttpAdapterClient; -import io.enmasse.systemtest.iot.MessageType; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.utils.IoTUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.client.HttpResponse; -import io.vertx.proton.ProtonDelivery; - -class CommandAndControlTest extends TestBase implements ITestIoTShared { - - private static Logger log = CustomLogger.getLogger(); - - private Endpoint deviceRegistryEndpoint; - private Endpoint httpAdapterEndpoint; - private DeviceRegistryClient registryClient; - private CredentialsRegistryClient credentialsClient; - - private String deviceId; - - private String authId; - - private String password; - - private HttpAdapterClient httpClient; - private String commandPayload; - private int ttd; - - @BeforeEach - void init() throws Exception { - - this.deviceRegistryEndpoint = IoTUtils.getDeviceRegistryManagementEndpoint(); - this.httpAdapterEndpoint = kubernetes.getExternalEndpoint("iot-http-adapter"); - this.registryClient = new DeviceRegistryClient(this.deviceRegistryEndpoint); - this.credentialsClient = new CredentialsRegistryClient(this.deviceRegistryEndpoint); - - // setup device information - this.deviceId = UUID.randomUUID().toString(); - this.authId = UUID.randomUUID().toString(); - this.password = UUID.randomUUID().toString(); - log.info("Registering device [deviceId]: {}, [authId]: {}, [password]: {}", deviceId, authId, password); - this.httpClient = new HttpAdapterClient(this.httpAdapterEndpoint, this.authId, sharedIoTResourceManager.getTenantId(), this.password); - - // set up new random device - this.registryClient.registerDevice(sharedIoTResourceManager.getTenantId(), this.deviceId); - this.credentialsClient.addCredentials(sharedIoTResourceManager.getTenantId(), this.deviceId, this.authId, this.password, null, HttpURLConnection.HTTP_NO_CONTENT); - - // setup payload - this.commandPayload = UUID.randomUUID().toString(); - this.ttd = 30; - - } - - @AfterEach - void closeHttpClient() { - if (this.httpClient != null) { - this.httpClient.close(); - this.httpClient = null; - } - } - - @Test - void testOneShotCommand() throws Exception { - - final AtomicReference>> sentFuture = new AtomicReference<>(); - - var f1 = setupMessagingReceiver(sentFuture, null); - - IoTUtils.waitForFirstSuccess(httpClient, MessageType.TELEMETRY); - - var response = sendTelemetryWithTtd(); - - assertTelemetryResponse(response); - - assertCloudTelemetryMessage(f1); - assertCommandMessageDeliveries(sentFuture.get()); - - } - - @Test - @Tag(ACCEPTANCE) - void testRequestResponseCommand() throws Exception { - - final var reqId = UUID.randomUUID().toString(); - final var replyToAddress = "command_response/" + sharedIoTResourceManager.getTenantId() + "/" + UUID.randomUUID().toString(); - - final AtomicReference>> sentFuture = new AtomicReference<>(); - - // set up command response consumer (before responding to telemetry) - var f3 = sharedIoTResourceManager.getAmqpClient().recvMessages(replyToAddress, 1); - - var f1 = setupMessagingReceiver(sentFuture, commandMessage -> { - commandMessage.setCorrelationId(reqId); - commandMessage.setReplyTo(replyToAddress); - }); - - IoTUtils.waitForFirstSuccess(httpClient, MessageType.TELEMETRY); - - var response = sendTelemetryWithTtd(); - - assertTelemetryResponse(response); - - // also assert response id - - var responseId = response.getHeader("hono-cmd-req-id"); - assertThat(responseId, notNullValue()); - - // send the reply to the command - - TestUtils.runUntilPass(5, () -> { - this.httpClient.send(COMMAND_RESPONSE, "/" + responseId, - new JsonObject().put("data", "command-response").toBuffer(), - is(HTTP_ACCEPTED), - request -> request.putHeader("hono-cmd-status", "202" /* accepted */), Duration.ofSeconds(5)); - }); - - assertCloudTelemetryMessage(f1); - assertCommandMessageDeliveries(sentFuture.get()); - - // assert command response message - cloud side - - var responses = f3.get(10, TimeUnit.SECONDS); - assertThat(responses, hasSize(1)); - var responseMsg = responses.get(0); - assertThat(responseMsg.getCorrelationId(), Is.is(reqId)); - assertThat(responseMsg.getBody(), instanceOf(Data.class)); - assertThat(new JsonObject(Buffer.buffer(((Data) responseMsg.getBody()).getValue().getArray())), Is.is(new JsonObject().put("data", "command-response"))); - assertThat(responseMsg.getApplicationProperties().getValue().get("status"), Is.is(202) /* accepted */); - - } - - private HttpResponse sendTelemetryWithTtd() throws Exception { - - // consumer link should be ready now ... send telemetry with "ttd" - - log.info("Send telemetry with TTD - ttd: {}", this.ttd); - - var response = TestUtils.runUntilPass(5, () -> { - return this.httpClient.send(TELEMETRY, null, is(HTTP_OK /* OK for command responses */), request -> { - // set "time to disconnect" - request.putHeader("hono-ttd", Integer.toString(this.ttd)); - }, Duration.ofSeconds(this.ttd + 5)); - }); - - log.info("Telemetry response: {}: {}", response.statusCode(), response.bodyAsString()); - - return response; - - } - - private Future> setupMessagingReceiver(final AtomicReference>> sentFuture, final Consumer messageCustomizer) { - - // setup telemetry consumer - - var f1 = sharedIoTResourceManager.getAmqpClient().recvMessages(new QueueTerminusFactory().getSource("telemetry/" + sharedIoTResourceManager.getTenantId()), msg -> { - - log.info("Received message: {}", msg); - - var ttdValue = msg.getApplicationProperties().getValue().get("ttd"); - - if (ttdValue == null) { - // this was the initial message, without waiting for commands - return false; - } - - var deviceId = msg.getApplicationProperties().getValue().get("device_id").toString(); - - // prepare message - - var commandMessage = Message.Factory.create(); - commandMessage.setSubject("CMD1"); - commandMessage.setMessageId(UUID.randomUUID().toString()); - - commandMessage.setContentType("application/octet-stream"); - commandMessage.setBody(new Data(Binary.create(ByteBuffer.wrap(this.commandPayload.getBytes())))); - commandMessage.setAddress("command/" + sharedIoTResourceManager.getTenantId() + "/" + deviceId); - - if (messageCustomizer != null) { - messageCustomizer.accept(commandMessage); - } - - // send request command - - log.info("Sending out command message"); - var f2 = sharedIoTResourceManager.getAmqpClient().sendMessage("command/" + sharedIoTResourceManager.getTenantId(), commandMessage) - .whenComplete((res, err) -> { - String strres = null; - if (res != null) { - strres = res.stream().map(ProtonDelivery::getRemoteState).map(Object::toString).collect(Collectors.joining(", ")); - } - log.info("Message result - res: {}, err:", // no need for final {}, as this is an exception - strres, err); - }); - sentFuture.set(f2); - log.info("Message underway"); - - // stop listening for more messages - - return true; - - }, Optional.empty()).getResult(); - return f1; - - } - - private void assertTelemetryResponse(final HttpResponse response) { - - // assert message - device side - - final var actualCommand = response.bodyAsString(); - assertThat(response.getHeader("hono-command"), Is.is("CMD1")); - assertThat(actualCommand, Is.is(this.commandPayload)); - - } - - private void assertCloudTelemetryMessage(Future> f1) throws InterruptedException, ExecutionException, TimeoutException { - - // assert message - cloud side - - // wait for the future of the sent message - var m1 = f1.get(10, TimeUnit.SECONDS); - - // dump messages - m1.forEach(m -> log.info("Message: {}", m)); - - // we expect two messages, the "test" message and the actual one - assertThat(m1, hasSize(2)); - // get the second message, the real one - var msg = m1.get(1); - - // message must have "ttd" set - var ttdValue = msg.getApplicationProperties().getValue().get("ttd"); - assertThat(ttdValue, instanceOf(Number.class)); - assertThat(ttdValue, Is.is(30)); - - } - - private void assertCommandMessageDeliveries(Future> messageFuture) throws InterruptedException, ExecutionException, TimeoutException { - - assertThat(messageFuture, notNullValue()); - - // assert command message deliveries - cloud side - - final List deliveries = messageFuture.get(10, TimeUnit.SECONDS); - assertThat(deliveries, hasSize(1)); - assertThat(deliveries.stream().map(ProtonDelivery::getRemoteState).collect(Collectors.toList()), - contains( - anyOf( - instanceOf(Released.class), // remove once issue eclipse/hono#1149 is fixed - instanceOf(Accepted.class)))); - - } - -} diff --git a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java b/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java deleted file mode 100644 index 30a07badaf9..00000000000 --- a/systemtests/src/test/java/io/enmasse/systemtest/isolated/CommonTest.java +++ /dev/null @@ -1,839 +0,0 @@ -/* - * Copyright 2018-2020, EnMasse authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.enmasse.systemtest.isolated; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import io.enmasse.address.model.Address; -import io.enmasse.address.model.AddressBuilder; -import io.enmasse.address.model.AddressSpace; -import io.enmasse.address.model.AddressSpaceBuilder; -import io.enmasse.admin.model.v1.AddressPlan; -import io.enmasse.admin.model.v1.AddressSpacePlan; -import io.enmasse.admin.model.v1.AddressSpacePlanBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfig; -import io.enmasse.admin.model.v1.BrokeredInfraConfigBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfigSpecAdminBuilder; -import io.enmasse.admin.model.v1.BrokeredInfraConfigSpecBrokerBuilder; -import io.enmasse.admin.model.v1.ResourceAllowance; -import io.enmasse.admin.model.v1.ResourceRequest; -import io.enmasse.admin.model.v1.StandardInfraConfig; -import io.enmasse.admin.model.v1.StandardInfraConfigBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecAdminBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecBrokerBuilder; -import io.enmasse.admin.model.v1.StandardInfraConfigSpecRouterBuilder; -import io.enmasse.config.LabelKeys; -import io.enmasse.systemtest.UserCredentials; -import io.enmasse.systemtest.amqp.AmqpClient; -import io.enmasse.systemtest.bases.TestBase; -import io.enmasse.systemtest.bases.isolated.ITestBaseIsolated; -import io.enmasse.systemtest.executor.ExecutionResultData; -import io.enmasse.systemtest.logs.CustomLogger; -import io.enmasse.systemtest.model.address.AddressType; -import io.enmasse.systemtest.model.addressplan.DestinationPlan; -import io.enmasse.systemtest.model.addressspace.AddressSpacePlans; -import io.enmasse.systemtest.model.addressspace.AddressSpaceType; -import io.enmasse.systemtest.platform.KubeCMDClient; -import io.enmasse.systemtest.platform.Kubernetes; -import io.enmasse.systemtest.platform.apps.SystemtestsKubernetesApps; -import io.enmasse.systemtest.shared.standard.QueueTest; -import io.enmasse.systemtest.time.TimeoutBudget; -import io.enmasse.systemtest.utils.AddressSpaceUtils; -import io.enmasse.systemtest.utils.AddressUtils; -import io.enmasse.systemtest.utils.PlanUtils; -import io.enmasse.systemtest.utils.TestUtils; -import io.fabric8.kubernetes.api.model.Pod; -import org.apache.qpid.proton.amqp.Binary; -import org.apache.qpid.proton.amqp.messaging.AmqpValue; -import org.apache.qpid.proton.amqp.messaging.Data; -import org.apache.qpid.proton.amqp.transport.DeliveryState.DeliveryStateType; -import org.apache.qpid.proton.message.Message; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.slf4j.Logger; - -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Random; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static io.enmasse.systemtest.TestTag.ISOLATED; -import static io.enmasse.systemtest.TestTag.NON_PR; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -@Tag(ISOLATED) -class CommonTest extends TestBase implements ITestBaseIsolated { - private static Logger log = CustomLogger.getLogger(); - - @Test - void testAccessLogs() throws Exception { - AddressSpace standard = new AddressSpaceBuilder() - .withNewMetadata() - .withName("mystandard") - .withNamespace(kubernetes.getInfraNamespace()) - .endMetadata() - .withNewSpec() - .withType(AddressSpaceType.STANDARD.toString()) - .withPlan(AddressSpacePlans.STANDARD_UNLIMITED) - .withNewAuthenticationService() - .withName("standard-authservice") - .endAuthenticationService() - .endSpec() - .build(); - resourcesManager.createAddressSpace(standard); - - Address dest = new AddressBuilder() - .withNewMetadata() - .withNamespace(standard.getMetadata().getNamespace()) - .withName(AddressUtils.generateAddressMetadataName(standard, "test-queue")) - .endMetadata() - .withNewSpec() - .withType("queue") - .withAddress("test-queue") - .withPlan(DestinationPlan.STANDARD_SMALL_QUEUE) - .endSpec() - .build(); - resourcesManager.setAddresses(dest); - - kubernetes.awaitPodsReady(standard.getMetadata().getNamespace(), new TimeoutBudget(5, TimeUnit.MINUTES)); - - Multimap podsContainersWithNoLog = HashMultimap.create(); - - kubernetes.listPods().stream().filter(pod -> !pod.getMetadata().getName().contains("none-authservice")).forEach(pod -> kubernetes.getContainersFromPod(pod.getMetadata().getNamespace(), pod.getMetadata().getName()).forEach(container -> { - String podNamespace = pod.getMetadata().getNamespace(); - String podName = pod.getMetadata().getName(); - String containerName = container.getName(); - log.info("Getting log from pod: {}, for container: {}", podName, containerName); - String podlog = kubernetes.getLog(podNamespace, podName, containerName); - - // Retry - diagnostic code to help understand a sporadic Ci failure. - if (podlog.isEmpty()) { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - log.info("(Retry) Getting log from pod: {}, for container: {}", podName, containerName); - podlog = kubernetes.getLog(podNamespace, podName, containerName); - } - - if (podlog.isEmpty()) { - podsContainersWithNoLog.put(podName, containerName); - } - - })); - - if (!podsContainersWithNoLog.isEmpty()) { - String podContainerNames = podsContainersWithNoLog.entries().stream().map(e -> String.format("%s-%s", e.getKey(), e.getValue())).collect(Collectors.joining(",")); - fail(String.format("%d pod container(s) had unexpectedly empty logs : %s ", podsContainersWithNoLog.size(), podContainerNames)); - } - } - - @Test - void testRestartComponents() throws Exception { - List

brokeredAddresses = AddressUtils.getAllBrokeredAddresses(brokered); - List
standardAddresses = AddressUtils.getAllStandardAddresses(standard); - - resourcesManager.setAddresses(brokeredAddresses.toArray(new Address[0])); - resourcesManager.setAddresses(standardAddresses.toArray(new Address[0])); - - getClientUtils().assertCanConnect(brokered, user, brokeredAddresses, resourcesManager); - getClientUtils().assertCanConnect(standard, user, standardAddresses, resourcesManager); - - log.info("------------------------------------------------------------"); - log.info("------------------- Start with restarting -------------------"); - log.info("------------------------------------------------------------"); - - List pods = kubernetes.listPods(); - int runningPodsBefore = pods.size(); - log.info("Number of running pods before restarting any: {}", runningPodsBefore); - for (Label label : labels) { - log.info("Restarting {}", label.labelValue); - KubeCMDClient.deletePodByLabel(label.getLabelName(), label.getLabelValue()); - Thread.sleep(30_000); - TestUtils.waitForExpectedReadyPods(kubernetes, kubernetes.getInfraNamespace(), runningPodsBefore, new TimeoutBudget(10, TimeUnit.MINUTES)); - assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - } - - log.info("Restarting whole enmasse"); - KubeCMDClient.deletePodByLabel("app", kubernetes.getEnmasseAppLabel()); - Thread.sleep(180_000); - TestUtils.waitForExpectedReadyPods(kubernetes, kubernetes.getInfraNamespace(), runningPodsBefore, new TimeoutBudget(10, TimeUnit.MINUTES)); - AddressUtils.waitForDestinationsReady(new TimeoutBudget(10, TimeUnit.MINUTES), - standardAddresses.toArray(new Address[0])); - assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - - //TODO: Uncomment when #2127 will be fixed - -// Pod qdrouter = pods.stream().filter(pod -> pod.getMetadata().getName().contains("qdrouter")).collect(Collectors.toList()).get(0); -// kubernetes.deletePod(environment.namespace(), qdrouter.getMetadata().getName()); -// assertSystemWorks(brokered, standard, user, brokeredAddresses, standardAddresses); - } - //https://github.com/EnMasseProject/enmasse/issues/3098 - - @Test - void testRestartAdminComponent() throws Exception { - List