import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URI;
import java.util.Map.Entry;
import java.util.Set;
}
private CompositeNodeWrapper createStructureWithRoot(String rootObjectName, JsonObject rootObject) {
- CompositeNodeWrapper firstNode = new CompositeNodeWrapper(rootObjectName);
+ CompositeNodeWrapper firstNode = new CompositeNodeWrapper(getNamespaceFrom(rootObjectName),
+ getLocalNameFrom(rootObjectName));
for (Entry<String, JsonElement> childOfFirstNode : rootObject.entrySet()) {
addChildToParent(childOfFirstNode.getKey(), childOfFirstNode.getValue(), firstNode);
}
private void addChildToParent(String childName, JsonElement childType, CompositeNodeWrapper parent) {
if (childType.isJsonObject()) {
- CompositeNodeWrapper child = new CompositeNodeWrapper(childName);
+ CompositeNodeWrapper child = new CompositeNodeWrapper(getNamespaceFrom(childName),
+ getLocalNameFrom(childName));
parent.addValue(child);
for (Entry<String, JsonElement> childOfChild : childType.getAsJsonObject().entrySet()) {
addChildToParent(childOfChild.getKey(), childOfChild.getValue(), child);
String value = childPrimitive.getAsString();
SimpleNodeWrapper child = null;
if (value.equals("[null]")) {
- child = new SimpleNodeWrapper(childName, null);
+ child = new SimpleNodeWrapper(getNamespaceFrom(childName), getLocalNameFrom(childName), null);
} else {
- child = new SimpleNodeWrapper(childName, value);
+ child = new SimpleNodeWrapper(getNamespaceFrom(childName), getLocalNameFrom(childName), value);
}
parent.addValue(child);
}
}
+
+ private URI getNamespaceFrom(String jsonElementName) {
+ int indexOfDelimeter = jsonElementName.lastIndexOf(':');
+ if (indexOfDelimeter == -1) {
+ return null;
+ }
+ return URI.create(jsonElementName.substring(0, indexOfDelimeter));
+ }
+
+ private String getLocalNameFrom(String jsonElementName) {
+ int indexOfDelimeter = jsonElementName.lastIndexOf(':');
+ if (indexOfDelimeter == -1) {
+ return jsonElementName;
+ }
+ return jsonElementName.substring(indexOfDelimeter + 1, jsonElementName.length());
+ }
+
}
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
Entity.entity("<SimpleNode>", new MediaType("application", "vnd.yang.api+xml")));
assertEquals(400, response.getStatus());
}
+
+ @Test
+ public void testXmlToCompositeNode404NotFound() {
+ URI uri = null;
+ try {
+ uri = new URI("/datastore/" + URLEncoder.encode("ietf-interfaces:interfaces/interface/eth0", Charsets.US_ASCII.name()).toString());
+ } catch (UnsupportedEncodingException | URISyntaxException e) {
+ e.printStackTrace();
+ }
+
+ when(brokerFacade.readOperationalData(any(InstanceIdentifier.class))).thenReturn(null);
+
+ Response response = target(uri.toASCIIString()).request(MediaTypes.API+RestconfService.XML).get();
+ assertEquals(404, response.getStatus());
+ }
@Override
protected Application configure() {