diff --git a/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedEventBroker.java b/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedEventBroker.java deleted file mode 100644 index 97476d08c7d..00000000000 --- a/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedEventBroker.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2017, 2022 Red Hat Inc and others. - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat Inc - initial API and implementation - *******************************************************************************/ -package org.eclipse.kapua.qa.common.utils; - -import java.time.Duration; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.activemq.artemis.core.config.Configuration; -import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; -import org.apache.activemq.artemis.jms.server.config.ConnectionFactoryConfiguration; -import org.apache.activemq.artemis.jms.server.config.JMSConfiguration; -import org.apache.activemq.artemis.jms.server.config.impl.ConnectionFactoryConfigurationImpl; -import org.apache.activemq.artemis.jms.server.config.impl.JMSConfigurationImpl; -import org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.kapua.commons.setting.system.SystemSettingKey; -import org.eclipse.kapua.qa.common.DBHelper; -import org.eclipse.kapua.qa.common.Suppressed; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.inject.Singleton; - -import io.cucumber.java.en.Given; - -@Singleton -public class EmbeddedEventBroker { - - private static final Logger logger = LoggerFactory.getLogger(EmbeddedEventBroker.class); - - private static final String DEFAULT_DATA_DIRECTORY_PREFIX = "target/artemis" + UUID.randomUUID(); - private static final String DEFAULT_DATA_DIRECTORY = DEFAULT_DATA_DIRECTORY_PREFIX + "/data/journal"; - - private static final int EXTRA_STARTUP_DELAY = Integer.getInteger("org.eclipse.kapua.qa.broker.extraStartupDelay", 0); - - private static Map> closables = new HashMap<>(); - - private DBHelper database; - - private static EmbeddedJMS jmsServer; - - @Given("^Start Event Broker$") - public void start() { - //set a default value if not set - if (StringUtils.isEmpty(System.getProperty(SystemSettingKey.EVENT_BUS_URL.key()))) { - System.setProperty(SystemSettingKey.EVENT_BUS_URL.key(), "amqp://127.0.0.1:5672"); - } - - logger.info("Starting new instance of Event Broker"); - try { - //start Artemis embedded - Configuration configuration = new ConfigurationImpl(); - configuration.setPersistenceEnabled(false); - configuration.setJournalDirectory(DEFAULT_DATA_DIRECTORY); - configuration.setSecurityEnabled(false); - configuration.addAcceptorConfiguration("amqp", - "tcp://127.0.0.1:5672?protocols=AMQP"); - configuration.addConnectorConfiguration("connector", "tcp://127.0.0.1:5672"); - JMSConfiguration jmsConfig = new JMSConfigurationImpl(); - ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName("cf").setConnectorNames(Arrays.asList("connector")).setBindings("cf"); - jmsConfig.getConnectionFactoryConfigurations().add(cfConfig); - - jmsServer = new EmbeddedJMS().setConfiguration(configuration).setJmsConfiguration(jmsConfig).start(); - - if (EXTRA_STARTUP_DELAY > 0) { - Thread.sleep(Duration.ofSeconds(EXTRA_STARTUP_DELAY).toMillis()); - } - } catch (RuntimeException e) { - throw e; - } catch (Exception e) { - logger.error("Failed to start Event Broker", e); - } - } - - @Given("^Stop Event Broker$") - public void stop() { - logger.info("Stopping Event Broker instance ..."); - try (final Suppressed s = Suppressed.withRuntimeException()) { - // close all resources - closables.values().stream().flatMap(values -> values.stream()).forEach(s::closeSuppressed); - // shut down broker - if (jmsServer != null) { - jmsServer.stop(); - jmsServer = null; - } - } catch (Exception e) { - logger.error("Failed to stop Event Broker", e); - } - if (EXTRA_STARTUP_DELAY > 0) { - try { - Thread.sleep(Duration.ofSeconds(EXTRA_STARTUP_DELAY).toMillis()); - } catch (InterruptedException e) { - if (logger.isDebugEnabled()) { - logger.debug("Wait interrupted!", e); - } - else { - logger.warn("Wait interrupted!"); - } - } - } - logger.info("Stopping Event Broker instance ... done!"); - } - -} diff --git a/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedJetty.java b/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedJetty.java deleted file mode 100644 index fd7e968a2fa..00000000000 --- a/qa/common/src/main/java/org/eclipse/kapua/qa/common/utils/EmbeddedJetty.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - *******************************************************************************/ -package org.eclipse.kapua.qa.common.utils; - -import org.eclipse.jetty.jmx.MBeanContainer; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker; -import org.eclipse.jetty.webapp.Configuration; -import org.eclipse.jetty.webapp.WebAppContext; -import org.eclipse.kapua.commons.setting.system.SystemSettingKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.cucumber.java.en.Given; - -import java.io.File; -import java.lang.management.ManagementFactory; -import java.net.InetSocketAddress; - -public class EmbeddedJetty { - - private static final Logger logger = LoggerFactory.getLogger(EmbeddedJetty.class); - - private static Server jetty; - - @Given("^Start Jetty Server on host \"(.*)\" at port \"(.+)\"$") - public void start(String host, int port) throws Exception { - // Switch back to default DB connection resolver - // as Jetty has its own class loader and has to access in memory DB over TCP - System.setProperty(SystemSettingKey.DB_JDBC_CONNECTION_URL_RESOLVER.key(), "DEFAULT"); - - InetSocketAddress address = new InetSocketAddress(host, port); - jetty = new Server(address); - logger.info("Starting Jetty " + jetty); - - // Setup JMX - MBeanContainer mbContainer = new MBeanContainer( - ManagementFactory.getPlatformMBeanServer()); - jetty.addBean(mbContainer); - - WebAppContext webapp = new WebAppContext(); - webapp.setContextPath("/"); - //File warFile = new File("../rest-api/web/target/api.war"); - String warFileName = System.getProperty("jetty.war.file"); - File warFile = new File(warFileName); - webapp.setWar(warFile.getAbsolutePath()); - webapp.addAliasCheck(new AllowSymLinkAliasChecker()); - - Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(jetty); - classlist.addBefore( - "org.eclipse.jetty.webapp.JettyWebXmlConfiguration", - "org.eclipse.jetty.annotations.AnnotationConfiguration" ); - - webapp.setAttribute( - "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", - ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$" ); - - jetty.setHandler(webapp); - - jetty.start(); - jetty.dumpStdErr(); - // Blocks - //jetty.join(); - } - - @Given("^Stop Jetty Server$") - public void stop() throws Exception { - logger.info("Stopping Jetty " + jetty); - - jetty.stop(); - System.setProperty(SystemSettingKey.DB_JDBC_CONNECTION_URL_RESOLVER.key(), "H2"); - } - -} diff --git a/qa/integration/src/test/java/org/eclipse/kapua/integration/rest/RunRestUserTest.java b/qa/integration/src/test/java/org/eclipse/kapua/integration/rest/RunRestUserTest.java deleted file mode 100644 index 315ad37e903..00000000000 --- a/qa/integration/src/test/java/org/eclipse/kapua/integration/rest/RunRestUserTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Eurotech - *******************************************************************************/ -package org.eclipse.kapua.integration.rest; - -import org.junit.runner.RunWith; - -import io.cucumber.junit.Cucumber; -import io.cucumber.junit.CucumberOptions; - -@RunWith(Cucumber.class) -@CucumberOptions( - features = "classpath:features/rest/user/RestUser.feature", - glue = { "org.eclipse.kapua.qa.common", - "org.eclipse.kapua.qa.integration.steps", - "org.eclipse.kapua.service.account.steps", - "org.eclipse.kapua.service.user.steps" - }, - plugin = { "pretty", - "html:target/cucumber/RestUser", - "json:target/RestUser_cucumber.json" - }, - monochrome = true) - -public class RunRestUserTest { - -} diff --git a/qa/integration/src/test/resources/features/rest/user/RestUser.feature b/qa/integration/src/test/resources/features/rest/user/RestUser.feature deleted file mode 100644 index 26ddc9d66bc..00000000000 --- a/qa/integration/src/test/resources/features/rest/user/RestUser.feature +++ /dev/null @@ -1,206 +0,0 @@ -############################################################################### -# Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others -# -# This program and the accompanying materials are made -# available under the terms of the Eclipse Public License 2.0 -# which is available at https://www.eclipse.org/legal/epl-2.0/ -# -# SPDX-License-Identifier: EPL-2.0 -# -# Contributors: -# Eurotech - initial API and implementation -############################################################################### -@rest - # this test is excluded from the CI process and, if launched, fails - # this because it contains major flaws and rest features should be tested with a brand new feature file -Feature: REST API tests for User - REST API test of Kapua User API. - - @setup - Scenario: Start event broker for all scenarios - Given Start Event Broker - And Start Jetty Server on host "127.0.0.1" at port "8081" - - Scenario: Simple Jetty with rest-api war - Jetty with api.war is already started, now just login with sys user and - call GET on users to retrieve list of all users. - - Given Server with host "127.0.0.1" on port "8081" - When REST POST call at "/v1/authentication/user" with JSON "{"password": "kapua-password", "username": "kapua-sys"}" - Then REST response containing AccessToken - When REST GET call at "/v1/_/users?offset=0&limit=50" - Then REST response contains list of Users - -# Commented out as it is not possible to set configuration of user account -# -# Scenario: Create account and user in that account -# -# Given Server with host "127.0.0.1" on port "8080" -# And REST POST call at "/v1/authentication/user" with JSON "{"password": "kapua-password", "username": "kapua-sys"}" -# And REST response containing AccessToken -# And REST POST call at "/v1/AQ/accounts" with JSON "{"expirationDate": "2030-02-21T12:05:00.000Z", "organizationName": "Org A", "organizationPersonName": "Person Name", "organizationEmail": "person@org-a.com", "organizationPhoneNumber": "555-123-456", "organizationAddressLine1": "Address A", "organizationAddressLine2": "NA", "organizationCity": "Ljubljana", "organizationZipPostCode": "1000", "organizationStateProvinceCounty": "Province", "organizationCountry": "Slovenia", "name": "Person Name","entityAttributes": {}, "scopeId": "1"}" -# Then REST response containing Account -# And REST POST call at "/v1/$lastAccountCompactId$/users" with JSON "{"displayName": "User A", "email": "user.a@comp-a.com", "phoneNumber": "555-123-456", "userType": "INTERNAL", "externalId": "", "expirationDate": "2030-02-21T12:05:00.000Z", "status": "ENABLED", "name": "usera", "entityAttributes": {}, "scopeId": "$lastAccountId$"}" -# - - Scenario: Bug when user can retrieve user in another account if it has other account's user id - Prepare two different accounts with each having single user. - Login into account A. - Fetch user in that account and keep his ID. - Login into account B and search for user from previous step with its ID. - - Given Server with host "127.0.0.1" on port "8081" -# ------ Service steps ------ - When I login as user with name "kapua-sys" and password "kapua-password" - And I configure account service - | type | name | value | - | boolean | infiniteChildEntities | true | - | integer | maxNumberChildEntities | 50 | - And I configure user service - | type | name | value | - | boolean | infiniteChildEntities | true | - | integer | maxNumberChildEntities | 5 | - | boolean | lockoutPolicy.enabled | false | - | integer | lockoutPolicy.maxFailures | 3 | - | integer | lockoutPolicy.resetAfter | 300 | - | integer | lockoutPolicy.lockDuration | 3 | - Given Account - | name | scopeId | - | account-a | 1 | - And Move step data "LastAccount" to "AccountA" - And I configure account service - | type | name | value | - | boolean | infiniteChildEntities | true | - | integer | maxNumberChildEntities | 5 | - And I configure user service - | type | name | value | - | boolean | infiniteChildEntities | true | - | integer | maxNumberChildEntities | 5 | - | boolean | lockoutPolicy.enabled | false | - | integer | lockoutPolicy.maxFailures | 3 | - | integer | lockoutPolicy.resetAfter | 300 | - | integer | lockoutPolicy.lockDuration | 3 | - And User A - | name | displayName | email | phoneNumber | status | userType | - | kapua-a | Kapua User A | kapua_a@kapua.com | +386 31 323 444 | ENABLED | INTERNAL | - And Move step data "LastUser" to "UserA" - And I add credentials - | name | password | enabled | - | kapua-a | ToManySecrets123# | true | - And Add permissions to the last created user - | domain | action | - | user | read | - | user | write | - | user | delete | - And Account - | name | scopeId | - | account-b | 1 | - And Move step data "LastAccount" to "AccountB" - And I configure user service - | type | name | value | - | boolean | infiniteChildEntities | true | - | integer | maxNumberChildEntities | 5 | - | boolean | lockoutPolicy.enabled | false | - | integer | lockoutPolicy.maxFailures | 3 | - | integer | lockoutPolicy.resetAfter | 300 | - | integer | lockoutPolicy.lockDuration | 3 | - And User B - | name | displayName | email | phoneNumber | status | userType | - | kapua-b | Kapua User B | kapua_b@kapua.com | +386 31 323 555 | ENABLED | INTERNAL | - And I add credentials - | name | password | enabled | - | kapua-b | ToManySecrets123# | true | - And Add permissions to the last created user - | domain | action | - | user | read | - | user | write | - | user | delete | - And I logout -# ------ Service steps ------ - Then REST POST call at "/v1/authentication/user" with JSON "{"password": "ToManySecrets123#", "username": "kapua-a"}" - And REST response containing AccessToken - And Move Account compact id from step data "AccountA" to "accountACompactId" - And Move User compact id from step data "UserA" to "userACompactId" - And REST GET call at "/v1/$accountACompactId$/users/$userACompactId$" - Then REST response containing User - Then REST POST call at "/v1/authentication/logout" with JSON "" - And Clear step data with key "tokenId" - And REST POST call at "/v1/authentication/user" with JSON "{"password": "ToManySecrets123#", "username": "kapua-b"}" - And REST response containing AccessToken - And Move Account compact id from step data "AccountB" to "accountBCompactId" - And REST GET call at "/v1/$accountBCompactId$/users/$lastUserCompactId$" - Then REST response code is 404 - - Scenario: Retrieve all users and check if limitExceed value is true - Login with sys user and call GET on users to retrieve list of all users. Specify a limit of 0 entries, - then the limitExceed value must be true. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - When REST GET call at "/v1/_/users?offset=0&limit=0" - Then REST response contains limitExceed field with value true - - Scenario: Retrieve all users and check if limitExceed value is false - Login with sys user and call GET on users to retrieve list of all users. Specify a limit of 50 entries, - then the limitExceed value must be false. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - When REST GET call at "/v1/_/users?offset=0&limit=50" - Then REST response contains limitExceed field with value false - - Scenario: Create a new user, then retrieve all users and check if limitExceed value is false - Login with sys user and call GET on users to retrieve list of all users. Specify a limit of 2 entries, - then the limitExceed value must be false. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - Given 1 new user created - When REST GET call at "/v1/_/users?offset=0&limit=2" - Then REST response contains limitExceed field with value false - - Scenario: Create two new users, then retrieve all users and check if limitExceed value is true - Login with sys user and call GET on users to retrieve list of all users. Specify a limit of 3 entries - then the limitExceed value must be true. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - Given 2 new users created - When REST GET call at "/v1/_/users?offset=0&limit=3" - Then REST response contains limitExceed field with value false - - Scenario: Create two new users, then retrieve all users specifying a offset of 2, then check if - limitExceed value is false. - Login with sys user and call GET on users to retrieve list of all users. Specify a offset of 2 - then the limitExceed value must be false. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - Given 2 new users created - When REST GET call at "/v1/_/users?offset=2" - Then REST response contains limitExceed field with value false - - Scenario: Create three new users, then retrieve all users specifying a offset of 2 and a limit of 1, - then check if limitExceed value is true. - Login with sys user and call GET on users to retrieve list of all users. Specify a offset of 2 - and a limit of 1, then the limitExceed value must be false. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - Given 3 new users created - When REST GET call at "/v1/_/users?offset=2&limit=1" - Then REST response contains limitExceed field with value false - - Scenario: Create 119 new users, then retrieve all users specifying a offset of 100 and limit of 50, - then check if limitExceed value is false. Login with sys user and call GET on users to retrieve list - of all users. Specify a offset of 100 and a limit of 50 entries then the limitExceed value must be false. - - Given Server with host "127.0.0.1" on port "8081" - Given An authenticated user - Given 119 new users created - When REST GET call at "/v1/_/users?limit=50&offset=100" - Then REST response contains limitExceed field with value false - - Scenario: Stop Jetty server for all scenarios - Given Stop Jetty Server - And Stop Event Broker