Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TACKLE-268 Enhancements after the review #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,19 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.ResourceArg;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.tackle.applicationinventory.entities.ApplicationImport;
import io.tackle.applicationinventory.entities.ImportSummary;
import io.tackle.applicationinventory.services.BusinessServiceService;
import io.tackle.applicationinventory.services.TagService;
import io.tackle.applicationinventory.services.WireMockControlsServices;
import io.tackle.commons.testcontainers.KeycloakTestResource;
import io.tackle.commons.testcontainers.PostgreSQLDatabaseTestResource;
import io.tackle.commons.tests.SecuredResourceTest;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.hamcrest.core.Is;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.mockito.Mockito;

import javax.inject.Inject;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
import javax.ws.rs.core.MediaType;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
Expand All @@ -53,77 +35,49 @@
@ResourceArg(name = KeycloakTestResource.REALM_NAME, value = "quarkus")
}
)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class Issue268Test extends SecuredResourceTest {

@Inject
UserTransaction userTransaction;

@InjectMock
@RestClient
TagService mockTagService;

@InjectMock
@RestClient
BusinessServiceService mockBusinessServiceService;
@QuarkusTestResource(WireMockControlsServices.class)
// https://issues.redhat.com/browse/TACKLE-268
public class IssueTACKLE268Test extends SecuredResourceTest {

@BeforeAll
public static void init() {
PATH = "/file/upload";
}

@Test
protected void testImportServiceLongCSVColumnValues() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
Mockito.when(mockTagService.getListOfTags(0, 1000)).thenReturn(Collections.emptySet());
Mockito.when(mockBusinessServiceService.getListOfBusinessServices(0, 1000)).thenReturn(Collections.emptySet());

protected void testImportServiceLongCSVColumnValues() {
ClassLoader classLoader = getClass().getClassLoader();
File importFile = new File(classLoader.getResource("long_characters_columns.csv").getFile());

Response response = given()
given()
.config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs("multipart/form-data", ContentType.JSON)))
.contentType(MediaType.MULTIPART_FORM_DATA)
.accept(MediaType.MULTIPART_FORM_DATA)
.multiPart("file", importFile)
.multiPart("fileName", "long_characters_columns.csv")
.when().post(PATH)
.then()
.log().all()
.statusCode(200).extract().response();

assertEquals(200, response.getStatusCode());
.statusCode(200);

given()
final long importSummaryId = Long.parseLong(given()
.accept("application/hal+json")
.when()
.get("/import-summary")
.then()
.statusCode(200)
.log().body()
.body("_embedded.'import-summary'[0].'importStatus'", is("Completed"));

given()
.accept("application/json")
.body("_embedded.import-summary.size()", is(1),
"_embedded.import-summary[0].importStatus", is("Completed"),
"_embedded.import-summary[0].validCount", is(1),
"_embedded.import-summary[0].invalidCount", is(2))
.extract().path("_embedded.import-summary[0].id").toString());

final String csv = given()
.accept("text/csv")
.queryParam("importSummaryId", importSummaryId)
.when()
.get("/import-summary")
.then()
.statusCode(200)
.log().body()
.body("size()", is(1),
"[0].'importStatus'", is("Completed"),
"[0].'validCount'", is(1),
"[0].'invalidCount'", is(2)
);

ImportSummary summary = ImportSummary.findAll().firstResult();

Response r =
given()
.accept("text/csv")
.when()
.get("/csv-export?importSummaryId=" + summary.id);

String csv = r.body().print();
.get("/csv-export")
.body()
.print();
String[] csvFields = csv.split(",");

int numberOfRows = (int) Arrays.stream(csvFields).filter("\n"::equals).count();
Expand All @@ -141,7 +95,7 @@ protected void testImportServiceLongCSVColumnValues() throws SystemException, No
.get("/application")
.then()
.statusCode(200)
.body("size()", Is.is(1))
.body("size()", is(1))
.extract()
.path("[0].id")
.toString());
Expand All @@ -154,11 +108,13 @@ protected void testImportServiceLongCSVColumnValues() throws SystemException, No
.then()
.statusCode(204);

userTransaction.begin();
ApplicationImport.deleteAll();
ImportSummary.deleteAll();
userTransaction.commit();
// Remove the import summary record (on cascade also the ApplicationImport entities will be deleted)
given()
.accept(ContentType.JSON)
.pathParam("id", importSummaryId)
.when()
.delete("/import-summary/{id}")
.then()
.statusCode(204);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.tackle.applicationinventory.services.issues;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeIssueTACKLE268IT extends IssueTACKLE268Test {}