Skip to content

Commit

Permalink
TACKLE-271: case insensitive headers now allowed in import csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
m-brophy committed Jun 29, 2021
1 parent 0833e85 commit c1c860f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tackle.applicationinventory.services;

import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
Expand Down Expand Up @@ -136,6 +137,8 @@ private List<ApplicationImport> writeFile(String content, String filename, Impor

private MappingIterator<ApplicationImport> decode(String inputFileContent) throws IOException{
CsvMapper mapper = new CsvMapper();
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES);
mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);

CsvSchema csvSchema = CsvSchema.emptySchema().withHeader();
String columnSeparator = ",";
Expand Down
104 changes: 104 additions & 0 deletions src/test/java/io/tackle/applicationimporter/ImportServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

@QuarkusTest
Expand Down Expand Up @@ -190,6 +191,109 @@ protected void testImportServicePost() throws SystemException, NotSupportedExcep

}


@Test
@Order(1)
protected void testImportServiceCaseInsensitiveColumnHeaders() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {

userTransaction.begin();
Set<Tag> tags = new HashSet<>() ;
Tag.TagType tagType1 = new Tag.TagType();
tagType1.id = "1";
tagType1.name = "Operating System";
Tag tag = new Tag();
tag.id = "1";
tag.name = "RHEL 8";
tag.tagType = tagType1;
tags.add(tag);
Tag.TagType tagType2 = new Tag.TagType();
tagType2.id = "2";
tagType2.name = "Database";
Tag tag1 = new Tag();
tag1.id = "2";
tag1.name = "Oracle";
tag1.tagType = tagType2;
tags.add(tag1);
Tag.TagType tagType3 = new Tag.TagType();
tagType3.id = "3";
tagType3.name = "Language";
Tag tag2 = new Tag();
tag2.id = "3";
tag2.name = "Java EE";
tag2.tagType = tagType3;
tags.add(tag2);
Tag.TagType tagType4 = new Tag.TagType();
tagType4.id = "4";
tagType4.name = "Runtime";
Tag tag3 = new Tag();
tag3.id = "3";
tag3.name = "Tomcat";
tag3.tagType = tagType4;
tags.add(tag3);
Mockito.when(mockTagService.getListOfTags()).thenReturn(tags);


Set<BusinessService> businessServices = new HashSet<>() ;
BusinessService businessService = new BusinessService();
businessService.id = "1";
businessService.name = "Food2Go";
businessServices.add(businessService);
Mockito.when(mockBusinessServiceService.getListOfBusinessServices()).thenReturn(businessServices);

ClassLoader classLoader = getClass().getClassLoader();
File importFile = new File(classLoader.getResource("mixed_case_column_headers.csv").getFile());


Response response = 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","mixed_case_column_headers.csv")
.when().post(PATH)
.then()
.log().all()
.statusCode(200).extract().response();

assertEquals(200, response.getStatusCode());
//check the correct number of application imports have been persisted
assertEquals(7, ApplicationImport.listAll().size());
userTransaction.commit();

given()
.accept("application/hal+json")
.queryParam("isValid", Boolean.TRUE)
.when()
.get("/application-import")
.then()
.statusCode(200)
.log().body()
.body("_embedded.'application-import'.size()", is(1));



given()
.accept("application/hal+json")
.queryParam("isValid", Boolean.TRUE)
.when()
.get("/application-import")
.then()
.statusCode(200)
.log().body()
.body("_embedded.'application-import'.size()", is(1));

ApplicationImport successful = ApplicationImport.find("isValid",true).firstResult();
Application newOne = Application.find("name",successful.getApplicationName()).firstResult();
assertTrue(newOne.tags.contains("2"));

userTransaction.begin();
ApplicationImport.deleteAll();
ImportSummary.deleteAll();
Application.deleteById(newOne.id);
userTransaction.commit();

}

@Test
@Order(2)
protected void testMapToApplicationRejected() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/mixed_case_column_headers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Record Type 1,application Name,Description,comments,business service,Tag Type 1,Tag 1,tag Type 2,tag 2,Tag Type 3,Tag 3,Tag Type 4,Tag 4
1,OrderHub,"Create, amend and cancel food orders",,Food2Go,Operating System,RHEL 8,Database,Oracle,Language,Java EE,Runtime,Tomcat
1,MenuManager,Food vendors maintain their menu and price data which is curated and presented to customers via Orderhub,,Food2Go,Operating System,Windows Server 2016,Database,SQL Server,Language,C# ASP .Net,,
1,HeadChef,Allocation of orders to restaurants for fulfillment then despatch,,Foot2Go,Operating System,RHEL 8,Database,Postgresql,Language,Java EE,Runtime,Spring Boot
1,Despatcher,Delivery service,,Foot2Go,Operating System,RHEL 8,Database,Postgresql,Language,Python,,
1,PocketMoney,Payment service,Incoming from orders and outgoing to delivery drivers,Payment Management,Operating System,Z/OS,Database,DB2,Language,COBOL,,
1,BeanCounter,Accounting Service,COTS ERP system,Accounting,Operating System,RHEL 8,Database,Oracle,Language,Java EE,Application Type,COTS
1,SmokeSignal,Notification Service,Updates customers regarding the progress of their orders. Allocates deliveries to despatch drivers,Foot2Go,Operating System,RHEL 8,Language,Python,DataCentre,London (UK),,

0 comments on commit c1c860f

Please sign in to comment.