changed api interaction to openapi generated jar

This commit is contained in:
Bogdan Volodarskiy 2021-06-16 11:59:46 +03:00
parent a7e1b7360c
commit 11e57b0221
4 changed files with 75 additions and 20629 deletions

View file

@ -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>

View file

@ -11,6 +11,7 @@
<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>
@ -147,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>

View file

@ -1,65 +1,45 @@
package com.provectus.kafka.ui.helpers;
import com.provectus.kafka.ui.base.TestConfiguration;
import com.provectus.kafka.ui.steps.kafka.KafkaSteps;
import lombok.SneakyThrows;
import net.minidev.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import com.provectus.kafka.ui.api.*;
import com.provectus.kafka.ui.api.model.*;
import com.provectus.kafka.ui.api.api.TopicsApi;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ApiHelper {
int partitions = 1;
short replicationFactor = 1;
int replicationFactor = 1;
String newTopic = "new-topic";
String baseURL = "http://localhost:8080/";
@SneakyThrows
private void sendRequest(String method, String additionalURL, JSONObject jsonObject){
URL url = new URL(baseURL+additionalURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Accept", "application/json");
switch (method) {
case "POST":
con.setRequestMethod("POST");
OutputStream os = con.getOutputStream();
os.write(jsonObject.toString().getBytes("UTF-8"));
os.close();
break;
case "DELETE":
con.setRequestMethod("DELETE");
con.getResponseMessage();
break;
private TopicsApi topicApi(){
ApiClient defaultClient = new ApiClient();
defaultClient.setBasePath(baseURL);
TopicsApi topicsApi = new TopicsApi(defaultClient);
return topicsApi;
}
assertTrue(con.getResponseCode()==200);
InputStream in = new BufferedInputStream(con.getInputStream());
String result = org.apache.commons.io.IOUtils.toString(in, "UTF-8");
in.close();
con.disconnect();
}
@SneakyThrows
public void createTopic(String clusterName, String topicName) {
JSONObject topic = new JSONObject();
topic.put("name",topicName);
topic.put("partitions",partitions);
topic.put("replicationFactor",replicationFactor);
sendRequest("POST","api/clusters/"+clusterName+"/topics",topic);
TopicCreation topic = new TopicCreation();
topic.setName(topicName);
topic.setPartitions(partitions);
topic.setReplicationFactor(replicationFactor);
topicApi().createTopic(clusterName,topic);
}
@SneakyThrows
public void deleteTopic(String clusterName, String topicName) {
sendRequest("DELETE","api/clusters/"+clusterName+"/topics/"+topicName,null);
topicApi().deleteTopic(clusterName,topicName);
}
}

File diff suppressed because it is too large Load diff