Increase code coverage in cps-service module
[cps.git] / cps-service / src / test / groovy / org / onap / cps / yang / YangTextSchemaSourceSetBuilderSpec.groovy
index 3b4d57d..2739281 100644 (file)
 
 package org.onap.cps.yang
 
-
 import org.onap.cps.TestUtils
 import org.onap.cps.spi.exceptions.ModelValidationException
-import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
 import org.opendaylight.yangtools.yang.common.Revision
 import spock.lang.Specification
 
+import java.nio.charset.StandardCharsets
+
 class YangTextSchemaSourceSetBuilderSpec extends Specification {
 
     def 'Building a valid YangTextSchemaSourceSet using #filenameCase filename.'() {
@@ -62,4 +62,16 @@ class YangTextSchemaSourceSetBuilderSpec extends Specification {
             'invalid-empty.yang'          | 'no valid content'     || ModelValidationException
             'invalid-missing-import.yang' | 'no dependency module' || ModelValidationException
     }
+
+    def 'Convert yang source to a YangTextSchemaSource.'() {
+        given: 'a yang source text'
+            def yangSourceText = TestUtils.getResourceFileContent('bookstore.yang')
+        when: 'convert it to a YangTextSchemaSource'
+            def result = YangTextSchemaSourceSetBuilder.toYangTextSchemaSource('some name', yangSourceText)
+        then: 'the converted object has correct properties'
+            assert result.toString() == '{identifier=RevisionSourceIdentifier [name=some name]}'
+            assert new String(result.openStream().readAllBytes(), StandardCharsets.UTF_8) ==  yangSourceText
+        and: 'it has no symbolic name'
+            assert result.getSymbolicName().isEmpty()
+    }
 }