Repository: provectus/kafka-ui
Issue: [e2e-check] [test-data-preparation] Creating new topic via API
Labels: scope/QA

e2e checks should be able to use entities(such as topics) created in previous steps. But for creating certain test state we shouldn't always bother UI, otherwise it'll make checks slow and brittle. 
We need step for creating topic via `kafka-ui` API

Issue comments:

Pull request review comments:
you should use generated api from openapi

Patch that resolved the issue:
diff --git a/kafka-ui-contract/pom.xml b/kafka-ui-contract/pom.xml
index 8c3ff23786c..b6700196f44 100644
--- a/kafka-ui-contract/pom.xml
+++ b/kafka-ui-contract/pom.xml
@@ -48,6 +48,29 @@
                         <artifactId>openapi-generator-maven-plugin</artifactId>
                         <version>${openapi-generator-maven-plugin.version}</version>
                         <executions>
+                            <execution>
+                                <id>generate-kafka-ui-client</id>
+                                <goals>
+                                    <goal>generate</goal>
+                                </goals>
+                                <configuration>
+                                    <inputSpec>${project.basedir}/src/main/resources/swagger/kafka-ui-api.yaml
+                                    </inputSpec>
+                                    <output>${project.build.directory}/generated-sources/kafka-ui-client</output>
+                                    <generatorName>java</generatorName>
+                                    <generateApiTests>false</generateApiTests>
+                                    <generateModelTests>false</generateModelTests>
+                                    <configOptions>
+                                        <modelPackage>com.provectus.kafka.ui.api.model</modelPackage>
+                                        <apiPackage>com.provectus.kafka.ui.api.api</apiPackage>
+                                        <sourceFolder>kafka-ui-client</sourceFolder>
+                                        <asyncNative>true</asyncNative>
+                                        <library>webclient</library>
+                                        <useBeanValidation>true</useBeanValidation>
+                                        <dateLibrary>java8</dateLibrary>
+                                    </configOptions>
+                                </configuration>
+                            </execution>
                             <execution>
                                 <id>generate-backend-api</id>
                                 <goals>
diff --git a/kafka-ui-e2e-checks/pom.xml b/kafka-ui-e2e-checks/pom.xml
index 74e93453cb9..e934fb6e289 100644
--- a/kafka-ui-e2e-checks/pom.xml
+++ b/kafka-ui-e2e-checks/pom.xml
@@ -11,9 +11,11 @@
 
     <artifactId>kafka-ui-e2e-checks</artifactId>
     <properties>
+        <kafka-ui-contract>0.1.1-SNAPSHOT</kafka-ui-contract>
         <junit.version>5.7.0</junit.version>
         <aspectj.version>1.9.6</aspectj.version>
         <allure.version>2.13.7</allure.version>
+        <json-smart.version>1.1.1</json-smart.version>
         <testcontainers.version>1.15.2</testcontainers.version>
         <selenide.version>5.16.2</selenide.version>
         <assertj.version>3.17.1</assertj.version>
@@ -32,6 +34,11 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>net.minidev</groupId>
+            <artifactId>json-smart</artifactId>
+            <version>${json-smart.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.kafka</groupId>
             <artifactId>kafka_2.13</artifactId>
@@ -141,6 +148,12 @@
             <artifactId>screen-diff-plugin</artifactId>
             <version>${allure.screendiff-plugin.version}</version>
         </dependency>
+        <dependency>
+            <groupId>com.provectus</groupId>
+            <artifactId>kafka-ui-contract</artifactId>
+            <version>${kafka-ui-contract}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>


Test patch:
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/base/BaseTest.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/base/BaseTest.java
index ebf90807880..a5ac78f5660 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/base/BaseTest.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/base/BaseTest.java
@@ -2,6 +2,7 @@
 
 import com.codeborne.selenide.Configuration;
 import com.codeborne.selenide.logevents.SelenideLogger;
+import com.provectus.kafka.ui.helpers.Helpers;
 import com.provectus.kafka.ui.pages.Pages;
 import com.provectus.kafka.ui.screenshots.Screenshooter;
 import com.provectus.kafka.ui.steps.Steps;
@@ -27,6 +28,7 @@ public class BaseTest {
 
   protected Steps steps = Steps.INSTANCE;
   protected Pages pages = Pages.INSTANCE;
+  protected Helpers helpers = Helpers.INSTANCE;
 
   private Screenshooter screenshooter = new Screenshooter();
 
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/ApiHelper.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/ApiHelper.java
new file mode 100644
index 00000000000..0008cd64e4e
--- /dev/null
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/ApiHelper.java
@@ -0,0 +1,47 @@
+package com.provectus.kafka.ui.helpers;
+
+import lombok.SneakyThrows;
+
+import com.provectus.kafka.ui.api.*;
+import com.provectus.kafka.ui.api.model.*;
+import com.provectus.kafka.ui.api.api.TopicsApi;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class ApiHelper {
+    int partitions = 1;
+    int replicationFactor = 1;
+    String newTopic = "new-topic";
+    String baseURL = "http://localhost:8080/";
+
+
+
+
+    @SneakyThrows
+    private TopicsApi topicApi(){
+        ApiClient defaultClient = new ApiClient();
+        defaultClient.setBasePath(baseURL);
+        TopicsApi topicsApi = new TopicsApi(defaultClient);
+        return topicsApi;
+        }
+
+
+
+
+    @SneakyThrows
+    public void createTopic(String clusterName, String topicName) {
+        TopicCreation topic = new TopicCreation();
+        topic.setName(topicName);
+        topic.setPartitions(partitions);
+        topic.setReplicationFactor(replicationFactor);
+        topicApi().createTopic(clusterName,topic).block();
+    }
+
+    @SneakyThrows
+    public void deleteTopic(String clusterName, String topicName) {
+        topicApi().deleteTopic(clusterName,topicName).block();
+    }
+
+}
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/Helpers.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/Helpers.java
new file mode 100644
index 00000000000..cda55a0cb25
--- /dev/null
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/helpers/Helpers.java
@@ -0,0 +1,11 @@
+package com.provectus.kafka.ui.helpers;
+
+
+
+public class Helpers {
+    public static final Helpers INSTANCE = new Helpers();
+
+    private Helpers(){}
+
+    public ApiHelper apiHelper = new ApiHelper();
+}
diff --git a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/topics/TopicTests.java b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/topics/TopicTests.java
index a6a97299f03..b32d9b992f1 100644
--- a/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/topics/TopicTests.java
+++ b/kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/topics/TopicTests.java
@@ -3,8 +3,12 @@
 import com.provectus.kafka.ui.base.BaseTest;
 import com.provectus.kafka.ui.pages.MainPage;
 import com.provectus.kafka.ui.steps.kafka.KafkaSteps;
+import com.provectus.kafka.ui.helpers.ApiHelper;
 import lombok.SneakyThrows;
-import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
 
 public class TopicTests extends BaseTest {
 
@@ -13,18 +17,18 @@ public class TopicTests extends BaseTest {
 
     @AfterEach
     @SneakyThrows
-    void  afterEach(){
-        steps.kafka.deleteTopic(KafkaSteps.Cluster.SECOND_LOCAL,NEW_TOPIC);
+        void  afterEach(){
+            helpers.apiHelper.deleteTopic("secondLocal","new-topic");
     }
 
     @SneakyThrows
     @DisplayName("should create a topic")
     @Test
     void createTopic(){
-        steps.kafka.createTopic(KafkaSteps.Cluster.SECOND_LOCAL,NEW_TOPIC);
+        helpers.apiHelper.createTopic("secondLocal","new-topic");
         pages.open()
                 .mainPage.shouldBeOnPage()
-        .goToSideMenu(KafkaSteps.Cluster.SECOND_LOCAL.getName(), MainPage.SideMenuOptions.TOPICS)
+        .goToSideMenu("secondLocal", MainPage.SideMenuOptions.TOPICS)
         .shouldBeTopic(NEW_TOPIC);
     }
 }