Merge branch 'feature/RM-4361_ReadRecordsRestAPI' into 'master'

Feature/rm 4361 read records rest api

Tests added to cover the story RM-4361 read records rest api

See merge request !718
This commit is contained in:
Rodica Sutu
2017-01-04 17:27:59 +00:00
4 changed files with 78 additions and 58 deletions

View File

@@ -71,10 +71,13 @@ public class RecordsAPI extends RMModelRequest
* <li>{@code recordId} does not exist</li> * <li>{@code recordId} does not exist</li>
* </ul> * </ul>
*/ */
//FIXME Add a generic method to support retrieving binary content
public <T> T getRecordContentText(String recordId) throws Exception public <T> T getRecordContentText(String recordId) throws Exception
{ {
mandatoryString("recordId", recordId); mandatoryString("recordId", recordId);
Response response = given().auth().basic(getRMRestWrapper().getTestUser().getUsername(), getRMRestWrapper().getTestUser().getPassword()) Response response = given().auth().basic(getRMRestWrapper().getTestUser().getUsername(),
getRMRestWrapper().getTestUser().getPassword()
)
.get("records/{recordId}/content", recordId) .get("records/{recordId}/content", recordId)
.andReturn(); .andReturn();
@@ -84,10 +87,10 @@ public class RecordsAPI extends RMModelRequest
} }
/** /**
* Get the html content for the electronic record * Get the content RestHtmlResponse(Response header and body) for the electronic record
* *
* @param recordId The id of the electronic record * @param recordId The id of the electronic record
* @return The content for the given record id * @return The body and the header for the record
* @throws Exception for the following cases: * @throws Exception for the following cases:
* <ul> * <ul>
* <li>{@code recordId} has no content</li> * <li>{@code recordId} has no content</li>
@@ -96,6 +99,8 @@ public class RecordsAPI extends RMModelRequest
* <li>{@code recordId} does not exist</li> * <li>{@code recordId} does not exist</li>
* </ul> * </ul>
*/ */
//FIXME Add a generic method to support retrieving binary content as we might end up
//FIXME with too many methods for differents content types
public RestHtmlResponse getRecordContent(String recordId) throws Exception public RestHtmlResponse getRecordContent(String recordId) throws Exception
{ {
mandatoryString("recordId", recordId); mandatoryString("recordId", recordId);

View File

@@ -331,31 +331,4 @@ public class BaseRMRestTest extends RestTest
return getFilePlanComponentAsUser(getAdminUser(), componentId); return getFilePlanComponentAsUser(getAdminUser(), componentId);
} }
/** }
* Create temp file with content
*
* @param name file name
* @return {@link File} file
*/
public static File createTempFile(final String name, String content)
{
try
{
// create file
final File file = File.createTempFile(name, ".txt");
// create writer
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder()))
{
// place content in file
writer.write(content);
}
return file;
} catch (Exception exception)
{
throw new RuntimeException("Unable to create test file.", exception);
}
}
}

View File

@@ -35,6 +35,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.springframework.http.HttpStatus.BAD_REQUEST; import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.OK;
@@ -53,6 +54,7 @@ import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentContent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentsCollection;
import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@@ -85,6 +87,7 @@ public class ReadRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build(); .build();
/** /**
* Given a record category or a container which can't contain records * Given a record category or a container which can't contain records
* When I try to read the children filtering the results to records * When I try to read the children filtering the results to records
@@ -107,7 +110,7 @@ public class ReadRecordTests extends BaseRMRestTest
) )
public void readRecordsFromInvalidContainers(String container) throws Exception public void readRecordsFromInvalidContainers(String container) throws Exception
{ {
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent electronicRecord = FilePlanComponent.builder() FilePlanComponent electronicRecord = FilePlanComponent.builder()
.name(ELECTRONIC_RECORD_NAME) .name(ELECTRONIC_RECORD_NAME)
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE.toString())
@@ -122,12 +125,12 @@ public class ReadRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build(); .build();
//create records //create records
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electronicRecord, container); filePlanComponentAPI.createFilePlanComponent(electronicRecord, container);
getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, container); filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, container);
// List children from API // List children from API
getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(container, "where=(isFile=true)") filePlanComponentAPI.listChildComponents(container, "where=(isFile=true)")
.assertThat()//check the list returned is empty .assertThat()//check the list returned is empty
.entriesListIsEmpty().assertThat().paginationExist(); .entriesListIsEmpty().assertThat().paginationExist();
//check response status code //check response status code
@@ -144,17 +147,19 @@ public class ReadRecordTests extends BaseRMRestTest
public void readRecordMetadata() throws Exception public void readRecordMetadata() throws Exception
{ {
String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder"; String RELATIVE_PATH = "/" + CATEGORY_NAME + getRandomAlphanumeric() + "/folder";
//create the containers from the relativePath FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
//create the containers from the relativePath
FilePlanComponent recordFolder = FilePlanComponent.builder() FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE.toString())
.relativePath(RELATIVE_PATH) .relativePath(RELATIVE_PATH)
.build(); .build();
String folderId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId(); String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder, FILE_PLAN_ALIAS.toString()).getId();
//create electronic record //create electronic record
String recordWithContentId = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId();
String recordWithContentId = filePlanComponentAPI.createElectronicRecord(electronicRecord, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME), folderId).getId();
//Get the record created //Get the record created
FilePlanComponent recordWithContent=getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(recordWithContentId, "include = "+IS_COMPLETED); FilePlanComponent recordWithContent= filePlanComponentAPI.getFilePlanComponent(recordWithContentId, "include = "+IS_COMPLETED);
//Check the metadata returned //Check the metadata returned
assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME)); assertTrue(recordWithContent.getName().startsWith(ELECTRONIC_RECORD_NAME));
assertTrue(recordWithContent.getIsFile()); assertTrue(recordWithContent.getIsFile());
@@ -168,9 +173,9 @@ public class ReadRecordTests extends BaseRMRestTest
assertStatusCode(OK); assertStatusCode(OK);
//create non-electronic record //create non-electronic record
String nonElectronicRecordId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, folderId).getId(); String nonElectronicRecordId = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, folderId).getId();
//Get the record created //Get the record created
FilePlanComponent nonElectronicRecord = getRestAPIFactory().getFilePlanComponentsAPI().getFilePlanComponent(nonElectronicRecordId, "include = " + IS_COMPLETED); FilePlanComponent nonElectronicRecord = filePlanComponentAPI.getFilePlanComponent(nonElectronicRecordId, "include = " + IS_COMPLETED);
//Check the metadata returned //Check the metadata returned
assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME)); assertTrue(nonElectronicRecord.getName().startsWith(NONELECTRONIC_RECORD_NAME));
@@ -196,19 +201,20 @@ public class ReadRecordTests extends BaseRMRestTest
{ {
String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric(); String RECORD_ELECTRONIC = "Record " + getRandomAlphanumeric();
String RELATIVE_PATH = "/"+CATEGORY_NAME+ getRandomAlphanumeric()+"/folder"; String RELATIVE_PATH = "/"+CATEGORY_NAME+ getRandomAlphanumeric()+"/folder";
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
//create the containers from the relativePath //create the containers from the relativePath
FilePlanComponent recordFolder = FilePlanComponent.builder() FilePlanComponent recordFolder = FilePlanComponent.builder()
.name(FOLDER_NAME) .name(FOLDER_NAME)
.nodeType(RECORD_FOLDER_TYPE.toString()) .nodeType(RECORD_FOLDER_TYPE.toString())
.relativePath(RELATIVE_PATH) .relativePath(RELATIVE_PATH)
.build(); .build();
String folderId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString()).getId(); String folderId = filePlanComponentAPI.createFilePlanComponent(recordFolder,FILE_PLAN_ALIAS.toString()).getId();
// //
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.name(RECORD_ELECTRONIC) .name(RECORD_ELECTRONIC)
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE.toString())
.build(); .build();
String recordId = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId(); String recordId = filePlanComponentAPI.createElectronicRecord(record, createTempFile(RECORD_ELECTRONIC, RECORD_ELECTRONIC), folderId).getId();
assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordId),RECORD_ELECTRONIC); assertEquals(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordId),RECORD_ELECTRONIC);
// Check status code // Check status code
@@ -218,7 +224,7 @@ public class ReadRecordTests extends BaseRMRestTest
.name(RECORD_ELECTRONIC) .name(RECORD_ELECTRONIC)
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE.toString())
.build(); .build();
String recordNoContentId = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(recordNoContent,folderId).getId(); String recordNoContentId = filePlanComponentAPI.createFilePlanComponent(recordNoContent,folderId).getId();
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordNoContentId).toString().isEmpty()); assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(recordNoContentId).toString().isEmpty());
assertStatusCode(OK); assertStatusCode(OK);
} }
@@ -232,13 +238,14 @@ public class ReadRecordTests extends BaseRMRestTest
{ {
String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric(); String NONELECTRONIC_RECORD_NAME = "Record nonelectronic" + getRandomAlphanumeric();
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.name(NONELECTRONIC_RECORD_NAME) .name(NONELECTRONIC_RECORD_NAME)
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME) .relativePath("/"+CATEGORY_NAME+getRandomAlphanumeric()+"/"+FOLDER_NAME)
.build(); .build();
String nonElectronicRecord= getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId(); String nonElectronicRecord= filePlanComponentAPI.createFilePlanComponent(record,FILE_PLAN_ALIAS.toString()).getId();
assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(nonElectronicRecord).toString().isEmpty()); assertTrue(getRestAPIFactory().getRecordsAPI().getRecordContentText(nonElectronicRecord).toString().isEmpty());
@@ -289,18 +296,18 @@ public class ReadRecordTests extends BaseRMRestTest
public void readRecordsFromFolders(String containerId) throws Exception public void readRecordsFromFolders(String containerId) throws Exception
{ {
final int NUMBER_OF_RECORDS = 5; final int NUMBER_OF_RECORDS = 5;
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
// Create Electronic Records // Create Electronic Records
ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>(); ArrayList<FilePlanComponent> children = new ArrayList<FilePlanComponent>();
for (int i = 0; i < NUMBER_OF_RECORDS; i++) for (int i = 0; i < NUMBER_OF_RECORDS; i++)
{ {
//build de electronic record //build the electronic record
FilePlanComponent record = FilePlanComponent.builder() FilePlanComponent record = FilePlanComponent.builder()
.name(ELECTRONIC_RECORD_NAME +i) .name(ELECTRONIC_RECORD_NAME +i)
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE.toString())
.build(); .build();
//create a child //create a child
FilePlanComponent child = getRestAPIFactory().getFilePlanComponentsAPI().createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId); FilePlanComponent child = filePlanComponentAPI.createElectronicRecord(record, createTempFile(ELECTRONIC_RECORD_NAME + i, ELECTRONIC_RECORD_NAME + i ), containerId);
children.add(child); children.add(child);
} }
//Create NonElectronicRecords //Create NonElectronicRecords
@@ -315,13 +322,13 @@ public class ReadRecordTests extends BaseRMRestTest
.nodeType(NON_ELECTRONIC_RECORD_TYPE.toString()) .nodeType(NON_ELECTRONIC_RECORD_TYPE.toString())
.build(); .build();
//create records //create records
FilePlanComponent child = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonelectronicRecord, containerId); FilePlanComponent child = filePlanComponentAPI.createFilePlanComponent(nonelectronicRecord, containerId);
children.add(child); children.add(child);
} }
// List children from API // List children from API
FilePlanComponentsCollection apiChildren = FilePlanComponentsCollection apiChildren =
(FilePlanComponentsCollection) getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(containerId).assertThat().entriesListIsNotEmpty(); (FilePlanComponentsCollection) filePlanComponentAPI.listChildComponents(containerId).assertThat().entriesListIsNotEmpty();
// Check status code // Check status code
assertStatusCode(OK); assertStatusCode(OK);
@@ -357,7 +364,8 @@ public class ReadRecordTests extends BaseRMRestTest
assertTrue(filePlanComponent.getName().startsWith(createdComponent.getName())); assertTrue(filePlanComponent.getName().startsWith(createdComponent.getName()));
assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType()); assertEquals(createdComponent.getNodeType(), filePlanComponent.getNodeType());
} catch (NoSuchElementException e) }
catch (NoSuchElementException e)
{ {
fail("No child element for " + filePlanComponent.getId()); fail("No child element for " + filePlanComponent.getId());
} }
@@ -374,6 +382,7 @@ public class ReadRecordTests extends BaseRMRestTest
public void readChildrenOnRecords() throws Exception public void readChildrenOnRecords() throws Exception
{ {
String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER"; String RELATIVE_PATH = "CATEGORY" + getRandomAlphanumeric() + "/FOLDER";
FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI();
FilePlanComponent electRecord = FilePlanComponent.builder() FilePlanComponent electRecord = FilePlanComponent.builder()
.name(ELECTRONIC_RECORD_NAME) .name(ELECTRONIC_RECORD_NAME)
.nodeType(CONTENT_TYPE.toString()) .nodeType(CONTENT_TYPE.toString())
@@ -389,18 +398,18 @@ public class ReadRecordTests extends BaseRMRestTest
.build(); .build();
//create records in Unfiled Container //create records in Unfiled Container
FilePlanComponent recordElecInUnfiled = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); FilePlanComponent recordElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(electRecord, UNFILED_RECORDS_CONTAINER_ALIAS.toString());
FilePlanComponent recordNonElecInUnfiled = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString()); FilePlanComponent recordNonElecInUnfiled = filePlanComponentAPI.createFilePlanComponent(nonElectronic, UNFILED_RECORDS_CONTAINER_ALIAS.toString());
// List children for the electronic Record // List children for the electronic Record
getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)") filePlanComponentAPI.listChildComponents(recordElecInUnfiled.getId(), "where=(isFile=true)")
//check the list returned is empty //check the list returned is empty
.assertThat().entriesListIsEmpty().assertThat().paginationExist(); .assertThat().entriesListIsEmpty().assertThat().paginationExist();
// Check status code // Check status code
assertStatusCode(OK); assertStatusCode(OK);
// List children for the nonElectronic Record // List children for the nonElectronic Record
getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordNonElecInUnfiled.getId(), "where=(isFile=true)") filePlanComponentAPI.listChildComponents(recordNonElecInUnfiled.getId(), "where=(isFile=true)")
//check the list returned is empty //check the list returned is empty
.assertThat().entriesListIsEmpty().assertThat().paginationExist(); .assertThat().entriesListIsEmpty().assertThat().paginationExist();
// Check status code // Check status code
@@ -411,11 +420,11 @@ public class ReadRecordTests extends BaseRMRestTest
nonElectronic.setRelativePath(RELATIVE_PATH); nonElectronic.setRelativePath(RELATIVE_PATH);
//create records in Unfiled Container //create records in Unfiled Container
FilePlanComponent recordElecFromRecordFolder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString()); FilePlanComponent recordElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(electRecord, FILE_PLAN_ALIAS.toString());
FilePlanComponent recordNonElecFromRecordFolder = getRestAPIFactory().getFilePlanComponentsAPI().createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString()); FilePlanComponent recordNonElecFromRecordFolder = filePlanComponentAPI.createFilePlanComponent(nonElectronic, FILE_PLAN_ALIAS.toString());
// List children for the electronic Record // List children for the electronic Record
getRestAPIFactory().getFilePlanComponentsAPI().listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)") filePlanComponentAPI.listChildComponents(recordElecFromRecordFolder.getId(), "where=(isFile=true)")
//check the list returned is empty //check the list returned is empty
.assertThat().entriesListIsEmpty().assertThat().paginationExist(); .assertThat().entriesListIsEmpty().assertThat().paginationExist();
// Check status code // Check status code

View File

@@ -30,6 +30,11 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent;
import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentProperties;
@@ -101,4 +106,32 @@ public class FilePlanComponentsUtil
.build()) .build())
.build(); .build();
} }
/**
* Create temp file with content
*
* @param name file name
* @return {@link File} file
*/
public static File createTempFile(final String name, String content)
{
try
{
// create file
final File file = File.createTempFile(name, ".txt");
// create writer
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, Charset.forName("UTF-8").newEncoder()))
{
// place content in file
writer.write(content);
}
return file;
} catch (Exception exception)
{
throw new RuntimeException("Unable to create test file.", exception);
}
}
} }