* Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Bell Canada.
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.yang
-
import org.onap.cps.TestUtils
import org.onap.cps.spi.exceptions.ModelValidationException
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.'() {
'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()
+ }
}