Skip to content

Commit

Permalink
Merge pull request #3 from mrizzi/carlosthe19916-TACKLE-268
Browse files Browse the repository at this point in the history
TACKLE-268 Enhancements after the review
  • Loading branch information
carlosthe19916 authored Aug 23, 2021
2 parents 1f2a65d + 4fdfa84 commit 1ae168d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 73 deletions.
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 {}

0 comments on commit 1ae168d

Please sign in to comment.