Skip to content

Commit 3a70b75

Browse files
committed
Restructures test instances for composition; Added parsing method by simply giving a path
1 parent decf6c1 commit 3a70b75

12 files changed

Lines changed: 94 additions & 53 deletions

File tree

src/main/java/de/vill/main/UVLModelFactory.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.vill.main;
22

3+
import de.vill.util.Util;
34
import uvl.UVLJavaLexer;
45
import uvl.UVLJavaParser;
56

@@ -93,7 +94,20 @@ public FeatureModel parse(String text, Map<String, String> fileLoader) throws Pa
9394
}
9495

9596
/**
96-
* This method parses the givel text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
97+
* This method parses an UVL model given a path to the UVL model. For imported submodels (if applicable) the directory of the UVL model is used
98+
* @param uvlModelPath path to uvl model
99+
* @return
100+
* @throws ParseError
101+
*/
102+
public FeatureModel parse(Path uvlModelPath) throws ParseError {
103+
String content = Util.readFileContent(uvlModelPath);
104+
String projectRootForImports = uvlModelPath.getParent().toString();
105+
106+
return parse(content, projectRootForImports);
107+
}
108+
109+
/**
110+
* This method parses the given text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
97111
*
98112
* @param text A String that describes a feature model in UVL notation.
99113
* @param path Path to the directory where all submodels are stored.
@@ -107,7 +121,7 @@ public FeatureModel parse(String text, String path) throws ParseError {
107121
}
108122

109123
/**
110-
* This method parses the givel text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
124+
* This method parses the given text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
111125
* It assumes that all the necessary submodels are in the current working directory.
112126
*
113127
* @param text A String that describes a feature model in UVL notation.

src/main/java/de/vill/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class Constants {
88
public static final String TRUE = "true";
99
public static final String UNDEF = "undef";
1010

11-
// Default attribtues
11+
// Default attributes
1212
public static final String TYPE_LEVEL_VALUE = "type_level_value";
1313
public static final String TYPE_LEVEL_LENGTH = "type_level_value_length";
1414

src/main/java/de/vill/util/Util.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import de.vill.config.Configuration;
44

5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
59
public class Util {
610
public static String indentEachLine(String text) {
711
StringBuilder result = new StringBuilder();
@@ -32,4 +36,12 @@ public static String addNecessaryQuotes(String reference) {
3236
}
3337
return result.toString();
3438
}
39+
40+
public static String readFileContent(Path file) {
41+
try {
42+
return new String(Files.readAllBytes(file));
43+
} catch (IOException e) {
44+
throw new RuntimeException(e);
45+
}
46+
}
3547
}

src/test/java/de/vill/parsing/ParsingTests.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class ParsingTests {
2626
+ File.separator;
2727
private static final String COMPLEX_MODEL_PREFIX = TEST_MODEL_PREFIX + File.separator + "complex" + File.separator;
2828

29+
private static final String COMPOSITION_MODEL_PREFIX = TEST_MODEL_PREFIX + "composition" + File.separator;
30+
31+
private static final String NESTED_MODEL_PREFIX = COMPOSITION_MODEL_PREFIX + "nested" + File.separator;
32+
2933
// Boolean level models
3034
private static final String SIMPLE_BOOLEAN = CONCEPTS_MODEL_PREFIX + "boolean.uvl";
3135
private static final String NAMESPACE = CONCEPTS_MODEL_PREFIX + "namespace.uvl";
@@ -53,6 +57,14 @@ public class ParsingTests {
5357
private static final String MISSING_REFRENCE = FAULTY_MODEL_PREFIX + "missingreference.uvl";
5458
private static final String WRONG_INDENT = FAULTY_MODEL_PREFIX + "wrongindent.uvl";
5559

60+
// Composition uvl models
61+
62+
private static final String COMPOSITION_ROOT = COMPOSITION_MODEL_PREFIX + "composition_root.uvl";
63+
64+
private static final String NESTED_COMPOSITION_ROOT = COMPOSITION_MODEL_PREFIX + "nested_main.uvl";
65+
66+
private static final String NESTED_SUB_COMPOSITION_ROOT = NESTED_MODEL_PREFIX + "nested_sub.uvl";
67+
5668
@Test
5769
void testBooleanModel() throws Exception {
5870
testModelParsing(SIMPLE_BOOLEAN);
@@ -120,6 +132,13 @@ void checkFaultyModels() throws Exception {
120132

121133
}
122134

135+
@Test
136+
void checkCompositionModels() throws Exception {
137+
testModelParsing(COMPOSITION_ROOT);
138+
testModelParsing(NESTED_COMPOSITION_ROOT);
139+
testModelParsing(NESTED_SUB_COMPOSITION_ROOT);
140+
}
141+
123142
private void testModelParsing(String path) {
124143
testModelParsing(path, true);
125144
}
@@ -130,8 +149,7 @@ public static FeatureModel testModelParsing(String path, boolean expectSuccess)
130149
FeatureModel result = null;
131150
boolean error = false;
132151
try {
133-
content = new String(Files.readAllBytes(Paths.get(path)));
134-
result = uvlModelFactory.parse(content);
152+
result = uvlModelFactory.parse(Paths.get(path));
135153
} catch (Exception e) {
136154
error = true;
137155
}

src/test/resources/composition/composition_root.uvl

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
imports
2+
composition_sub1
3+
4+
features
5+
Computer
6+
optional
7+
"RAM-module"
8+
mandatory
9+
"SATA-Devices"
10+
[0..3]
11+
HDD
12+
SSD
13+
"DVD-drive"
14+
"Card-reader"
15+
"Blu-ray-drive"
16+
composition_sub1.CPU
17+
PSU {abstract true}
18+
alternative
19+
strong_PSU
20+
weak_PSU
21+
22+
constraints
23+
SSD => strong_PSU
24+
"DVD-drive" <=> composition_sub1.brand & composition_sub1.fmIntel.feature1 & composition_sub1.composition_sub1_sub2.feature2

src/test/resources/composition/composition_sub1.uvl renamed to src/test/resources/parsing/composition/composition_sub1.uvl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
include
2-
SAT-level
3-
SMT-level
4-
5-
namespace composition_sub1
6-
71
imports
82
composition_sub1_sub1 as fmIntel
93
composition_sub1_sub2
@@ -21,7 +15,6 @@ features
2115
Bit32 {bit 32}
2216

2317
constraints
24-
Bit64 => fmIntel.Intel
2518
fmIntel.feature1 & fmIntel.feature2 <=> (Bit64) | !composition_sub1_sub2.feature2
2619
Bit64.bit + Bit32.bit > 32
2720
fmIntel.feature1.power - fmIntel.feature2.power == 25

src/test/resources/composition/composition_sub1_sub1.uvl renamed to src/test/resources/parsing/composition/composition_sub1_sub1.uvl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
include
2-
SAT-level
3-
4-
namespace composition_sub1_sub1
5-
61
features
72
Intel
83
mandatory

src/test/resources/composition/composition_sub1_sub2.uvl renamed to src/test/resources/parsing/composition/composition_sub1_sub2.uvl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
include
2-
SAT-level
3-
4-
namespace composition_sub1_sub2
5-
61
features
72
AMD
83
mandatory
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
features
2+
Nested
3+
optional
4+
N1
5+
N2

0 commit comments

Comments
 (0)