import static org.junit.Assert.assertTrue;
import com.google.common.collect.Sets;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
-import java.net.URI;
+import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Optional;
import javax.ws.rs.core.MediaType;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
+import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class JsonBodyReaderTest extends AbstractBodyReaderTest {
+ private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
+ XMLNamespace.of("instance:identifier:module"), Revision.of("2014-01-17"));
- private final JsonNormalizedNodeBodyReader jsonBodyReader;
- private static SchemaContext schemaContext;
+ private static EffectiveModelContext schemaContext;
- private static final QNameModule INSTANCE_IDENTIFIER_MODULE_QNAME = QNameModule.create(
- URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
+ private final JsonNormalizedNodeBodyReader jsonBodyReader;
public JsonBodyReaderTest() throws Exception {
super(schemaContext);
- this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
+ this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointService);
}
@Override
public void moduleSubContainerAugmentDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
- final Module augmentModule = schemaContext.findModules(new URI("augment:module")).iterator().next();
+ final Module augmentModule = schemaContext.findModules(XMLNamespace.of("augment:module")).iterator().next();
final QName contAugmentQName = QName.create(augmentModule.getQNameModule(), "cont-augment");
final YangInstanceIdentifier.AugmentationIdentifier augII = new YangInstanceIdentifier.AugmentationIdentifier(
Sets.newHashSet(contAugmentQName));
public void moduleSubContainerChoiceAugmentDataPostTest() throws Exception {
final DataSchemaNode dataSchemaNode = schemaContext
.getDataChildByName(QName.create(INSTANCE_IDENTIFIER_MODULE_QNAME, "cont"));
- final Module augmentModule = schemaContext.findModules(new URI("augment:module")).iterator().next();
+ final Module augmentModule = schemaContext.findModules(XMLNamespace.of("augment:module")).iterator().next();
final QName augmentChoice1QName = QName.create(augmentModule.getQNameModule(), "augment-choice1");
final QName augmentChoice2QName = QName.create(augmentChoice1QName, "augment-choice2");
final QName containerQName = QName.create(augmentChoice1QName, "case-choice-case-container1");
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, dataII);
}
+ @Test
+ public void testRangeViolation() throws Exception {
+ mockBodyReader("netconf786:foo", this.jsonBodyReader, false);
+
+ final InputStream inputStream = new ByteArrayInputStream(("{\n"
+ + " \"netconf786:foo\": {\n"
+ + " \"bar\": 100\n"
+ + " }\n"
+ + "}").getBytes(StandardCharsets.UTF_8));
+
+ assertRangeViolation(() -> jsonBodyReader.readFrom(null, null, null, this.mediaType, null, inputStream));
+ }
+
private static void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext, final YangInstanceIdentifier dataNodeIdent) {
assertEquals(dataSchemaNode, nnContext.getInstanceIdentifierContext().getSchemaNode());