Skip to content
Snippets Groups Projects
Commit 10a586ba authored by Detailleur's avatar Detailleur
Browse files

[NRRPLT-8288] test import experiments

parent a7430f95
No related branches found
No related tags found
No related merge requests found
<ns1:bibi
xmlns:ns1="http://schemas.humanbrainproject.eu/SP10/2014/BIBI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:brainModel>
<ns1:file>braitenberg.py</ns1:file>
<ns1:populations from="0" population="sensors" to="5" xsi:type="ns1:Range" />
<ns1:populations from="5" population="actors" to="8" xsi:type="ns1:Range" />
<ns1:populations from="0" population="record" to="8" xsi:type="ns1:Range" />
</ns1:brainModel>
<ns1:bodyModel robotId="husky">husky_model/model.sdf</ns1:bodyModel>
<ns1:transferFunction src="all_neurons_spike_monitor.py" xsi:type="ns1:PythonTransferFunction" />
<ns1:transferFunction src="left_wheel_neuron_rate_monitor.py" xsi:type="ns1:PythonTransferFunction" />
<ns1:transferFunction src="linear_twist.py" xsi:type="ns1:PythonTransferFunction" />
<ns1:transferFunction src="eye_sensor_transmit.py" xsi:type="ns1:PythonTransferFunction" />
</ns1:bibi>
\ No newline at end of file
<ExD
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.humanbrainproject.eu/SP10/2014/ExDConfig" xsi:schemaLocation="http://schemas.humanbrainproject.eu/SP10/2014/ExDConfig ../ExDConfFile.xsd">
<name>Holodeck Husky Braitenberg experiment</name>
<thumbnail>ExDXMLExample.jpg</thumbnail>
<description>This experiment loads the Husky robot from Clearpath Robotics in the Holodeck environment.
If the user starts the experiment, the Braitenberg vehicle network is executed
and the robot will turn around itself in place, until the camera detects a red color. Then,
the robot will move towards the colored object. In this experiment, the user can interact
and change the color of both screens by clicking on them with the right mouse button.</description>
<tags>husky robotics holodeck braitenberg</tags>
<timeout>840</timeout>
<configuration type="3d-settings" src="ExDXMLExample.ini" />
<configuration type="brainvisualizer" src="brainvisualizer.json" />
<configuration type="user-interaction-settings" src="ExDXMLExample.uis" />
<maturity>production</maturity>
<environmentModel src="virtual_room.sdf">
<robotPose robotId="husky" x="0.0" y="0.0" z="0.5" roll="0.0" pitch="-0.0" yaw="3.14159265359" />
</environmentModel>
<bibiConf src="bibi_configuration.bibi" />
<cameraPose>
<cameraPosition x="5.056825994369357" y="-1.0210998541555323" z="2.697598759953974" />
<cameraLookAt x="0" y="0" z="0.49999" />
</cameraPose>
<cloneDate>2021-07-05T15:20:29</cloneDate>
</ExD>
\ No newline at end of file
[
{
"webkitRelativePath": "./mock_experiment_configuration.exc",
"type": "exc"
},
{
"webkitRelativePath": "./mock_bibi_configuration.bibi",
"type": "bibi"
}
]
\ No newline at end of file
{
"deletedFolders":[0,1],
"addedFolders": [2]
}
\ No newline at end of file
[
{
"zipBaseFolderName": "0",
"destFolderName": "1"
},
{
"zipBaseFolderName": "0",
"destFolderName": "2"
}
]
\ No newline at end of file
...@@ -27,7 +27,7 @@ test('should emit an event on network error', () => { ...@@ -27,7 +27,7 @@ test('should emit an event on network error', () => {
jest.spyOn(DialogService.instance, 'networkError').mockImplementation(() => { jest.spyOn(DialogService.instance, 'networkError').mockImplementation(() => {
return Promise.resolve(); return Promise.resolve();
}); });
let NetworkError = MockDialog let NetworkError = MockDialog;
let confirmNetworkError = (startingNetwork) => { let confirmNetworkError = (startingNetwork) => {
expect(startingNetwork).toEqual(NetworkError); expect(startingNetwork).toEqual(NetworkError);
...@@ -47,7 +47,7 @@ test('should emit an event on data error', () => { ...@@ -47,7 +47,7 @@ test('should emit an event on data error', () => {
jest.spyOn(DialogService.instance, 'dataError').mockImplementation(() => { jest.spyOn(DialogService.instance, 'dataError').mockImplementation(() => {
return Promise.resolve(); return Promise.resolve();
}); });
let DataError = MockDialog let DataError = MockDialog;
let confirmDataError = (startingData) => { let confirmDataError = (startingData) => {
expect(startingData).toEqual(DataError); expect(startingData).toEqual(DataError);
...@@ -67,7 +67,7 @@ test('should emit an event on simulation error', () => { ...@@ -67,7 +67,7 @@ test('should emit an event on simulation error', () => {
jest.spyOn(DialogService.instance, 'simulationError').mockImplementation(() => { jest.spyOn(DialogService.instance, 'simulationError').mockImplementation(() => {
return Promise.resolve(); return Promise.resolve();
}); });
let SimulationError = MockDialog let SimulationError = MockDialog;
let confirmSimulationError = (startingSimulation) => { let confirmSimulationError = (startingSimulation) => {
expect(startingSimulation).toEqual(SimulationError); expect(startingSimulation).toEqual(SimulationError);
...@@ -87,7 +87,7 @@ test('should emit an event on progress notification', () => { ...@@ -87,7 +87,7 @@ test('should emit an event on progress notification', () => {
jest.spyOn(DialogService.instance, 'progressNotification').mockImplementation(() => { jest.spyOn(DialogService.instance, 'progressNotification').mockImplementation(() => {
return Promise.resolve(); return Promise.resolve();
}); });
let ProgressNotification = MockDialog let ProgressNotification = MockDialog;
let confirmProgressNotification = (startingProgress) => { let confirmProgressNotification = (startingProgress) => {
expect(startingProgress).toEqual(ProgressNotification); expect(startingProgress).toEqual(ProgressNotification);
...@@ -107,8 +107,7 @@ test('should emit an event on warning notification', () => { ...@@ -107,8 +107,7 @@ test('should emit an event on warning notification', () => {
jest.spyOn(DialogService.instance, 'warningNotification').mockImplementation(() => { jest.spyOn(DialogService.instance, 'warningNotification').mockImplementation(() => {
return Promise.resolve(); return Promise.resolve();
}); });
let WarningNotification = MockDialog;
let WarningNotification = MockDialog
let confirmWarningNotification = (startingWarning) => { let confirmWarningNotification = (startingWarning) => {
expect(startingWarning).toEqual(WarningNotification); expect(startingWarning).toEqual(WarningNotification);
......
...@@ -5,9 +5,9 @@ import '@testing-library/jest-dom'; ...@@ -5,9 +5,9 @@ import '@testing-library/jest-dom';
import 'jest-fetch-mock'; import 'jest-fetch-mock';
import ImportExperimentService from '../import-experiment-service'; import ImportExperimentService from '../import-experiment-service';
import MockEvent from '../../../../mocks/mock-event'
import MockResponse from '../../../../mocks/mock-response' import MockScanStorageResponse from '../../../../mocks/mock_scan_storage_response.json';
import MockResponses from '../../../../mocks/mock-responses' import MockZipResponses from '../../../../mocks/mock_zip_responses.json';
test('makes sure that invoking the constructor fails with the right message', () => { test('makes sure that invoking the constructor fails with the right message', () => {
expect(() => { expect(() => {
...@@ -18,3 +18,14 @@ test('makes sure that invoking the constructor fails with the right message', () ...@@ -18,3 +18,14 @@ test('makes sure that invoking the constructor fails with the right message', ()
}).toThrowError(Error('Use ImportExperimentService.instance')); }).toThrowError(Error('Use ImportExperimentService.instance'));
}); });
test('makes sure zip responses are encapsulated in an object', async () => {
let importZipResponses = {zipBaseFolderName:['0', '0'], destFolderName:['1', '2'], numberOfZips: 2};
expect(await ImportExperimentService.instance.getImportZipResponses(
MockZipResponses.map((response) => new Response(JSON.stringify(response))))).toStrictEqual(importZipResponses);
});
test('makes sure storage response is prepared', async () => {
let scanStorageResponse = {deletedFoldersNumber:2, addedFoldersNumber:1, deletedFolders:'0, 1', addedFolders:'2' };
expect(await ImportExperimentService.instance.getScanStorageResponse(
new Response(JSON.stringify(MockScanStorageResponse)))).toStrictEqual(scanStorageResponse);
});
\ No newline at end of file
...@@ -9,7 +9,7 @@ const scanStorageURL = `${config.api.proxy.url}${endpoints.proxy.storage.scanSto ...@@ -9,7 +9,7 @@ const scanStorageURL = `${config.api.proxy.url}${endpoints.proxy.storage.scanSto
/** /**
* The Import Experiment Service performs the requests (Extract), * The Import Experiment Service performs the requests (Extract),
* processes data such as zip or folder (Transform), * processes data such as zip or folder (Transform),
* and passes them to the Import Experiment Component (Load). * and passes them to the Import Experiment Component (Load).
* Errors are handled by communicating witht he Error Handler Service. * Errors are handled by communicating witht he Error Handler Service.
*/ */
...@@ -53,13 +53,13 @@ export default class ImportExperimentService extends HttpService { ...@@ -53,13 +53,13 @@ export default class ImportExperimentService extends HttpService {
return _instance; return _instance;
} }
getImportZipResponses(responses) { async getImportZipResponses(responses) {
let importZipResponses = { let importZipResponses = {
zipBaseFolderName: [], zipBaseFolderName: [],
destFolderName: [] destFolderName: []
}; };
importZipResponses.numberOfZips = responses.length; importZipResponses.numberOfZips = responses.length;
responses.forEach(async response =>{ await responses.forEach(async response =>{
response = await response.json(); response = await response.json();
importZipResponses['zipBaseFolderName'].push(response['zipBaseFolderName']); importZipResponses['zipBaseFolderName'].push(response['zipBaseFolderName']);
importZipResponses['destFolderName'].push(response['destFolderName']); importZipResponses['destFolderName'].push(response['destFolderName']);
...@@ -91,6 +91,7 @@ export default class ImportExperimentService extends HttpService { ...@@ -91,6 +91,7 @@ export default class ImportExperimentService extends HttpService {
} }
let promises = []; let promises = [];
Array.from(files).forEach(file => { Array.from(files).forEach(file => {
console.log(file);
promises.push( promises.push(
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
let reader = new FileReader(); let reader = new FileReader();
...@@ -140,7 +141,7 @@ export default class ImportExperimentService extends HttpService { ...@@ -140,7 +141,7 @@ export default class ImportExperimentService extends HttpService {
}); });
} }
readZippedExperimentExperiment(event) { readZippedExperiment(event) {
let files = event.target.files; let files = event.target.files;
let zipFiles = []; let zipFiles = [];
Array.from(files).forEach(file => { Array.from(files).forEach(file => {
...@@ -157,7 +158,7 @@ export default class ImportExperimentService extends HttpService { ...@@ -157,7 +158,7 @@ export default class ImportExperimentService extends HttpService {
} }
importZippedExperiment(event) { importZippedExperiment(event) {
let promises = this.readZippedExperimentExperiment(event) let promises = this.readZippedExperiment(event)
.then(zipContents => .then(zipContents =>
zipContents.map(zipContent => zipContents.map(zipContent =>
this.httpRequestPOST(importExperimentURL, zipContent, options) this.httpRequestPOST(importExperimentURL, zipContent, options)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment