-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed feature include logic. Keep synthetic 'case' if leaf is disabled.
- Loading branch information
Showing
5 changed files
with
231 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...lsp/io.typefox.yang/src/test/java/io/typefox/yang/tests/processor/FeatureContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.typefox.yang.tests.processor; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.Collections; | ||
|
||
import org.junit.Test; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import io.typefox.yang.processor.FeatureEvaluationContext; | ||
|
||
public class FeatureContextTest { | ||
|
||
@Test | ||
public void testIncludeOneFeature() { | ||
FeatureEvaluationContext ctx = new FeatureEvaluationContext(Lists.newArrayList("module:feature1"), | ||
Collections.emptyList()); | ||
assertTrue(ctx.isActive("module:", "module:feature1", "feature1")); | ||
assertFalse(ctx.isActive("module:", "module:feature2", "feature2")); | ||
} | ||
|
||
@Test | ||
public void testIncludeNoFeature() { | ||
FeatureEvaluationContext ctx = new FeatureEvaluationContext(Lists.newArrayList("module:"), | ||
Collections.emptyList()); | ||
assertFalse(ctx.isActive("module:", "module:feature1", "feature1")); | ||
assertFalse(ctx.isActive("module:", "module:feature2", "feature2")); | ||
} | ||
@Test | ||
public void testIncludeTwoFeatures() { | ||
FeatureEvaluationContext ctx = new FeatureEvaluationContext(Lists.newArrayList("module:feature1,feature2"), | ||
Collections.emptyList()); | ||
assertTrue(ctx.isActive("module:", "module:feature1", "feature1")); | ||
assertTrue(ctx.isActive("module:", "module:feature2", "feature2")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,8 @@ public void processModules_TreeTest_FeatureInclude() throws IOException { | |
String expectation = null; | ||
|
||
// CLI tree test expect output like: | ||
// pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang -F example-system-ext: | ||
// pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang -F | ||
// example-system-ext: | ||
try (InputStream in = this.getClass().getClassLoader() | ||
.getResourceAsStream("processor/expectation/expectation-feature-only-example.txt"); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in))) { | ||
|
@@ -86,6 +87,33 @@ public void processModules_TreeTest_FeatureInclude() throws IOException { | |
|
||
} | ||
|
||
/* | ||
* enables ietf-keystore:local-definitions-supported feature. | ||
* Which effectively disables other ietf-keystore: features: | ||
* ietf-keystore:keystore-supported and ietf-keystore:key-generation | ||
*/ | ||
@Test | ||
public void processModules_TreeTest_FeatureIncludeOne() throws IOException { | ||
|
||
var sysModule = processData(true, newArrayList("ietf-keystore:local-definitions-supported"), null, | ||
"[email protected]"); | ||
|
||
String expectation = null; | ||
|
||
// CLI tree test expect output like: | ||
// pyang -f tree -p . [email protected] --deviation-module | ||
// example-system-ext.yang -F ietf-keystore:local-definitions-supported | ||
try (InputStream in = this.getClass().getClassLoader() | ||
.getResourceAsStream("processor/expectation/expectation-one-feature-only-example.txt"); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in))) { | ||
var writer = new StringWriter(); | ||
br.transferTo(writer); | ||
expectation = writer.getBuffer().toString(); | ||
} | ||
assertEqualsReduceSpace(expectation, new DataTreeSerializer().serialize(sysModule.get()).toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void processModules_TreeTest_FeatureExclude() throws IOException { | ||
|
||
|
@@ -94,7 +122,8 @@ public void processModules_TreeTest_FeatureExclude() throws IOException { | |
String expectation = null; | ||
|
||
// CLI tree test expect output like: | ||
// pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang -X example-system-ext:ldap-posix-filter | ||
// pyang -f tree ietf-system.yang --deviation-module example-system-ext.yang -X | ||
// example-system-ext:ldap-posix-filter | ||
try (InputStream in = this.getClass().getClassLoader() | ||
.getResourceAsStream("processor/expectation/expectation-feature-exclude-f.txt"); | ||
BufferedReader br = new BufferedReader(new InputStreamReader(in))) { | ||
|
@@ -150,6 +179,12 @@ private Optional<ModuleData> processData(boolean withDeviation) throws IOExcepti | |
|
||
private Optional<ModuleData> processData(boolean withDeviation, List<String> includedFeatures, | ||
List<String> excludedFeatures) throws IOException { | ||
return processData(withDeviation, includedFeatures, excludedFeatures, "ietf-system.yang"); | ||
} | ||
|
||
private Optional<ModuleData> processData(boolean withDeviation, List<String> includedFeatures, | ||
List<String> excludedFeatures, String entryFile) throws IOException { | ||
|
||
var resourceMap = Maps.<String, Resource>newHashMap(); | ||
List<String> files = newArrayList(); | ||
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream("processor"); | ||
|
@@ -163,7 +198,7 @@ private Optional<ModuleData> processData(boolean withDeviation, List<String> inc | |
|
||
files.stream().forEach(it -> resourceMap.put(it, | ||
resourceSet.createResource(URI.createFileURI("src/test/resources/processor/" + it)))); | ||
var resource = resourceMap.get("ietf-system.yang"); | ||
var resource = resourceMap.get(entryFile); | ||
resource.load(resourceSet.getLoadOptions()); | ||
EcoreUtil.resolveAll(resource); | ||
assertNoErrors(resource); | ||
|
@@ -176,16 +211,16 @@ private Optional<ModuleData> processData(boolean withDeviation, List<String> inc | |
}); | ||
|
||
ProcessedDataModel dataTree = new YangProcessor().process(modules, includedFeatures, excludedFeatures); | ||
var sysModule = dataTree.getModules().stream().filter(mod -> "ietf-system".equals(mod.getSimpleName())).findFirst(); | ||
var sysModule = dataTree.getModules().stream().filter(mod -> mod.getUri().endsWith(entryFile)).findFirst(); | ||
return sysModule; | ||
|
||
} | ||
|
||
private void assertEqualsReduceSpace(String expectation, String actual) { | ||
if(expectation != null) { | ||
if (expectation != null) { | ||
expectation = expectation.replaceAll(" {4,}", " "); | ||
} | ||
if(actual != null) { | ||
if (actual != null) { | ||
actual = actual.replaceAll(" {4,}", " "); | ||
} | ||
assertEquals(expectation, actual); | ||
|
92 changes: 92 additions & 0 deletions
92
...ox.yang/src/test/resources/processor/expectation/expectation-one-feature-only-example.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module: ietf-keystore | ||
+--rw keystore | ||
+--rw asymmetric-keys | ||
| +--rw asymmetric-key* [name] | ||
| | +--rw name string | ||
| | +--rw algorithm iasa:asymmetric-algorithm-type | ||
| | +--rw public-key-format? identityref | ||
| | +--rw public-key binary | ||
| | +--rw private-key-format? identityref | ||
| | +--rw (private-key-type) | ||
| | | +--:(private-key) | ||
| | | | +--rw private-key? binary | ||
| | | +--:(hidden-private-key) | ||
| | | | +--rw hidden-private-key? empty | ||
| | | +--:(ks:encrypted-private-key) | ||
| | | +--rw ks:encrypted-private-key | ||
| | | +--rw (ks:key-type) | ||
| | | | +--:(ks:symmetric-key-ref) | ||
| | | | +--:(ks:asymmetric-key-ref) | ||
| | | +--rw ks:value? binary | ||
| | +--rw certificates | ||
| | | +--rw certificate* [name] | ||
| | | +--rw name string | ||
| | | +--rw cert? end-entity-cert-cms | ||
| | | +---n certificate-expiration | ||
| | | +-- expiration-date yang:date-and-time | ||
| | +---x generate-certificate-signing-request | ||
| | +---w input | ||
| | | +---w subject binary | ||
| | | +---w attributes? binary | ||
| | +--ro output | ||
| | +--ro certificate-signing-request binary | ||
| +---x generate-asymmetric-key | ||
| +---w input | ||
| | +---w algorithm iasa:asymmetric-algorithm-type | ||
| | +---w encrypt-with! | ||
| | +---w (key-type) | ||
| | +--:(symmetric-key-ref) | ||
| | +--:(asymmetric-key-ref) | ||
| +--ro output | ||
| +--ro algorithm iasa:asymmetric-algorithm-type | ||
| +--ro public-key-format? identityref | ||
| +--ro public-key binary | ||
| +--ro private-key-format? identityref | ||
| +--ro (private-key-type) | ||
| +--:(private-key) | ||
| | +--rw private-key? binary | ||
| +--:(hidden-private-key) | ||
| | +--rw hidden-private-key? empty | ||
| +--:(ks:encrypted-private-key) | ||
| +--rw ks:encrypted-private-key | ||
| +--rw (ks:key-type) | ||
| | +--:(ks:symmetric-key-ref) | ||
| | +--:(ks:asymmetric-key-ref) | ||
| +--rw ks:value? binary | ||
+--rw symmetric-keys | ||
+--rw symmetric-key* [name] | ||
| +--rw name string | ||
| +--rw algorithm isa:symmetric-algorithm-type | ||
| +--rw key-format? identityref | ||
| +--rw (key-type) | ||
| +--:(key) | ||
| | +--rw key? binary | ||
| +--:(hidden-key) | ||
| | +--rw hidden-key? empty | ||
| +--:(ks:encrypted-key) | ||
| +--rw ks:encrypted-key | ||
| +--rw (ks:key-type) | ||
| | +--:(ks:symmetric-key-ref) | ||
| | +--:(ks:asymmetric-key-ref) | ||
| +--rw ks:value? binary | ||
+---x generate-symmetric-key | ||
+---w input | ||
| +---w algorithm isa:symmetric-algorithm-type | ||
| +---w encrypt-with! | ||
| +---w (key-type) | ||
| +--:(symmetric-key-ref) | ||
| +--:(asymmetric-key-ref) | ||
+--ro output | ||
+--ro algorithm isa:symmetric-algorithm-type | ||
+--ro key-format? identityref | ||
+--ro (key-type) | ||
+--:(key) | ||
| +--rw key? binary | ||
+--:(hidden-key) | ||
| +--rw hidden-key? empty | ||
+--:(ks:encrypted-key) | ||
+--rw ks:encrypted-key | ||
+--rw (ks:key-type) | ||
| +--:(ks:symmetric-key-ref) | ||
| +--:(ks:asymmetric-key-ref) | ||
+--rw ks:value? binary |