Commit 0856dfb2 authored by Christopher Jan-Steffen Brix's avatar Christopher Jan-Steffen Brix
Browse files

Cleanup, added tests

parent 68085f1f
Pipeline #104068 failed with stages
in 19 minutes and 43 seconds
......@@ -20,6 +20,8 @@
*/
package de.monticore.lang.monticar.cnnarch;
import de.se_rwth.commons.logging.Log;
import java.io.*;
import java.net.URL;
import java.util.Objects;
......@@ -28,10 +30,19 @@ import java.util.Properties;
public class DataPathConfigParser{
private String configTargetPath;
private String configFileName;
private String configFileName;
private Properties properties;
public DataPathConfigParser(String configPath) {
setConfigPath(configPath);
properties = new Properties();
try
{
properties.load(new FileInputStream(configTargetPath));
} catch(IOException e)
{
Log.error("Config file " + configPath + " could not be found");
}
}
public String getConfigPath() {
......@@ -46,20 +57,10 @@ public class DataPathConfigParser{
}
public String getDataPath(String modelName) {
Properties properties = new Properties();
try
{
properties.load(new FileInputStream(configTargetPath));
}catch(IOException e)
{
e.printStackTrace();
}
for (String key: properties.stringPropertyNames())
{
if (key.equals(modelName))
return properties.getProperty(key);
String path = properties.getProperty(modelName);
if(path == null) {
Log.error("Data path config file did not specify a path for component '" + modelName + "'");
}
return "empty string";
return path;
}
}
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.monticar.cnnarch;
import de.monticore.lang.monticar.cnnarch._symboltable.*;
import de.monticore.lang.monticar.cnnarch.predefined.AllPredefinedVariables;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import org.junit.Before;
import org.junit.Test;
import static de.monticore.lang.monticar.cnnarch.ParserTest.ENABLE_FAIL_QUICK;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class DataPathConfigParserTest extends AbstractSymtabTest {
@Before
public void setUp() {
// ensure an empty log
Log.getFindings().clear();
Log.enableFailQuick(ENABLE_FAIL_QUICK);
}
@Test
public void testDataPathConfigParserValidComponent() {
DataPathConfigParser parser = new DataPathConfigParser("src/test/resources/architectures/data_paths.txt");
String data_path = parser.getDataPath("ComponentName");
assertTrue("Wrong data path returned", data_path.equals("/path/to/training/data"));
}
@Test
public void testDataPathConfigParserInvalidComponent() {
DataPathConfigParser parser = new DataPathConfigParser("src/test/resources/architectures/data_paths.txt");
String data_path = parser.getDataPath("NotExistingComponent");
assertTrue("For not listed components, null should be returned", data_path == null);
assertTrue(Log.getFindings().size() == 1);
}
@Test
public void testDataPathConfigParserInvalidPath() {
DataPathConfigParser parser = new DataPathConfigParser("invalid/path/data_paths.txt");
assertTrue(Log.getFindings().size() == 1);
}
}
ComponentName /path/to/training/data
\ No newline at end of file
Markdown is supported
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