Skip to content

Commit

Permalink
Issue #57 test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszm committed Sep 13, 2022
1 parent ea19702 commit a84b51f
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4 deletions.
10 changes: 10 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
<artifactId>args4j</artifactId>
<version>2.33</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-parser</artifactId>
<version>[1.0.31,1.9.99)</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main/java/com/mrv/yangtools/codegen/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public enum AuthenticationMechanism {
BASIC, NONE
}

OutputStream out = System.out;
public OutputStream out = System.out;

public static void main(String[] args) {

Expand All @@ -104,13 +104,13 @@ public static void main(String[] args) {
}
}

protected void init() throws FileNotFoundException {
void init() throws FileNotFoundException {
if (output != null && output.trim().length() > 0) {
out = new FileOutputStream(output);
}
}

protected void generate() throws IOException, ReactorException {
void generate() throws IOException, ReactorException {
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.yang");

final SchemaContext context = buildSchemaContext(yangDir, p -> matcher.matches(p.getFileName()));
Expand Down
47 changes: 47 additions & 0 deletions cli/src/test/java/com/mrv/yangtools/codegen/main/Issue57.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.mrv.yangtools.codegen.main;

import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import org.junit.Assert;
import org.junit.Test;
import org.kohsuke.args4j.CmdLineParser;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Issue57 {

@Test
public void test() throws Exception {

String path = Paths.get(Issue57.class.getResource("/bug_57/").toURI()).toAbsolutePath().toString();

List<String> args = Stream.of(
"-yang-dir",
path
).collect(Collectors.toList());

Main main = new Main();
CmdLineParser parser = new CmdLineParser(main);
parser.parseArgument(args);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
main.out = baos;
main.init();
main.generate();

Swagger swagger = new SwaggerParser().parse(new String(baos.toByteArray(), StandardCharsets.UTF_8));

Set<String> result = swagger.getDefinitions().keySet().stream()
.filter(s -> s.endsWith("Input"))
.collect(Collectors.toSet());
Set<String> expected = Stream.of("objects.createobject.Input", "objects.updateobject.Input")
.collect(Collectors.toSet());
Assert.assertEquals(expected, result);

}
}
36 changes: 36 additions & 0 deletions cli/src/test/resources/bug_57/input.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module objects {

yang-version "1.1";
namespace "urn:objects";
prefix "obje";

grouping id_1 {
leaf id_1 {
type "string";
}
}

grouping id_2 {
leaf id_2 {
type "string";
}
}

rpc create-object {
input {
uses id_1;
uses id_2;
}
output {
}
}

rpc update-object {
input {
uses id_1;
uses id_2;
}
output {
}
}
}
2 changes: 1 addition & 1 deletion swagger-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>${swagger.version}</version>
<version>[1.0.31,1.9.99)</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mrv.yangtools.codegen.issues;

import com.mrv.yangtools.codegen.AbstractItTest;
import org.junit.Assert;
import org.junit.Test;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Issue57 extends AbstractItTest {
@Test
public void testIssue57() {
swaggerFor(p -> p.getParent().getFileName().toString().equals("bug_57"));
Set<String> result = swagger.getDefinitions().keySet().stream()
.filter(s -> s.endsWith("Input"))
.collect(Collectors.toSet());
Set<String> expected = Stream.of("objects.createobject.Input", "objects.updateobject.Input")
.collect(Collectors.toSet());
Assert.assertEquals(expected, result);
}
}
36 changes: 36 additions & 0 deletions swagger-generator/src/test/resources/bug_57/input.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module objects {

yang-version "1.1";
namespace "urn:objects";
prefix "obje";

grouping id_1 {
leaf id_1 {
type "string";
}
}

grouping id_2 {
leaf id_2 {
type "string";
}
}

rpc create-object {
input {
uses id_1;
uses id_2;
}
output {
}
}

rpc update-object {
input {
uses id_1;
uses id_2;
}
output {
}
}
}

0 comments on commit a84b51f

Please sign in to comment.