+ assertEquals(200, get(uri, MediaType.APPLICATION_XML));
+
+ uri = createUri("/config/", "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1");
+ assertEquals(200, get(uri, MediaType.APPLICATION_XML));
+ }
+
+ @Test
+ public void getDataMountPointIntoHighestElement() throws UnsupportedEncodingException, URISyntaxException {
+ when(
+ brokerFacade.readConfigurationDataBehindMountPoint(any(MountInstance.class),
+ any(InstanceIdentifier.class))).thenReturn(prepareCnDataForMountPointTest());
+ MountInstance mountInstance = mock(MountInstance.class);
+ when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
+ MountService mockMountService = mock(MountService.class);
+ when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(mountInstance);
+
+ ControllerContext.getInstance().setMountService(mockMountService);
+
+ String uri = createUri("/config/", "ietf-interfaces:interfaces/interface/0/yang-ext:mount/");
+ assertEquals(200, get(uri, MediaType.APPLICATION_XML));
+ }
+
+ // /modules
+ @Test
+ public void getModulesTest() throws UnsupportedEncodingException, FileNotFoundException {
+ ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
+
+ String uri = createUri("/modules", "");
+
+ Response response = target(uri).request("application/yang.api+json").get();
+ validateModulesResponseJson(response);
+
+ response = target(uri).request("application/yang.api+xml").get();
+ validateModulesResponseXml(response);
+ }
+
+ // /modules/module
+ @Test
+ public void getModuleTest() throws FileNotFoundException, UnsupportedEncodingException {
+ ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
+
+ String uri = createUri("/modules/module/module2/2014-01-02", "");
+
+ Response response = target(uri).request("application/yang.api+xml").get();
+ assertEquals(200, response.getStatus());
+ String responseBody = response.readEntity(String.class);
+ assertTrue("Module2 in xml wasn't found", prepareXmlRegex("module2", "2014-01-02", "module:2", responseBody)
+ .find());
+ String[] split = responseBody.split("<module");
+ assertEquals("<module element is returned more then once",2,split.length);
+
+ response = target(uri).request("application/yang.api+json").get();
+ assertEquals(200, response.getStatus());
+ responseBody = response.readEntity(String.class);
+ assertTrue("Module2 in json wasn't found", prepareJsonRegex("module2", "2014-01-02", "module:2", responseBody)
+ .find());
+ split = responseBody.split("\"module\"");
+ assertEquals("\"module\" element is returned more then once",2,split.length);
+
+ }
+
+ // /operations
+ @Test
+ public void getOperationsTest() throws FileNotFoundException, UnsupportedEncodingException {
+ ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
+
+ String uri = createUri("/operations", "");
+
+ Response response = target(uri).request("application/yang.api+xml").get();
+ assertEquals(200, response.getStatus());
+ String responseBody = response.readEntity(String.class);
+ assertTrue("Xml response for /operations dummy-rpc1-module1 is incorrect",
+ validateOperationsResponseXml(responseBody, "dummy-rpc1-module1", "module:1").find());
+ assertTrue("Xml response for /operations dummy-rpc2-module1 is incorrect",
+ validateOperationsResponseXml(responseBody, "dummy-rpc2-module1", "module:1").find());
+ assertTrue("Xml response for /operations dummy-rpc1-module2 is incorrect",
+ validateOperationsResponseXml(responseBody, "dummy-rpc1-module2", "module:2").find());
+ assertTrue("Xml response for /operations dummy-rpc2-module2 is incorrect",
+ validateOperationsResponseXml(responseBody, "dummy-rpc2-module2", "module:2").find());
+
+ response = target(uri).request("application/yang.api+json").get();
+ assertEquals(200, response.getStatus());
+ responseBody = response.readEntity(String.class);
+ assertTrue("Json response for /operations dummy-rpc1-module1 is incorrect",
+ validateOperationsResponseJson(responseBody, "dummy-rpc1-module1", "module1").find());
+ assertTrue("Json response for /operations dummy-rpc2-module1 is incorrect",
+ validateOperationsResponseJson(responseBody, "dummy-rpc2-module1", "module1").find());
+ assertTrue("Json response for /operations dummy-rpc1-module2 is incorrect",
+ validateOperationsResponseJson(responseBody, "dummy-rpc1-module2", "module2").find());
+ assertTrue("Json response for /operations dummy-rpc2-module2 is incorrect",
+ validateOperationsResponseJson(responseBody, "dummy-rpc2-module2", "module2").find());
+
+ }
+
+ // /operations/pathToMountPoint/yang-ext:mount
+ @Test
+ public void getOperationsBehindMountPointTest() throws FileNotFoundException, UnsupportedEncodingException {
+ ControllerContext controllerContext = ControllerContext.getInstance();
+ controllerContext.setGlobalSchema(schemaContextModules);
+
+ MountInstance mountInstance = mock(MountInstance.class);
+ when(mountInstance.getSchemaContext()).thenReturn(schemaContextBehindMountPoint);
+ MountService mockMountService = mock(MountService.class);
+ when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(mountInstance);
+
+ controllerContext.setMountService(mockMountService);
+
+ String uri = createUri("/operations/", "ietf-interfaces:interfaces/interface/0/yang-ext:mount/");
+
+ Response response = target(uri).request("application/yang.api+xml").get();
+ assertEquals(200, response.getStatus());
+ String responseBody = response.readEntity(String.class);
+ assertTrue("Xml response for /operations/mount_point rpc-behind-module1 is incorrect",
+ validateOperationsResponseXml(responseBody, "rpc-behind-module1", "module:1:behind:mount:point").find());
+ assertTrue("Xml response for /operations/mount_point rpc-behind-module2 is incorrect",
+ validateOperationsResponseXml(responseBody, "rpc-behind-module2", "module:2:behind:mount:point").find());
+
+ response = target(uri).request("application/yang.api+json").get();
+ assertEquals(200, response.getStatus());
+ responseBody = response.readEntity(String.class);
+ assertTrue("Json response for /operations/mount_point rpc-behind-module1 is incorrect",
+ validateOperationsResponseJson(responseBody, "rpc-behind-module1", "module1-behind-mount-point").find());
+ assertTrue("Json response for /operations/mount_point rpc-behind-module2 is incorrect",
+ validateOperationsResponseJson(responseBody, "rpc-behind-module2", "module2-behind-mount-point").find());
+
+ }
+
+ private Matcher validateOperationsResponseJson(String searchIn, String rpcName, String moduleName) {
+ StringBuilder regex = new StringBuilder();
+ regex.append("^");
+
+ regex.append(".*\\{");
+ regex.append(".*\"");
+
+ // operations prefix optional
+ regex.append("(");
+ regex.append("ietf-restconf:");
+ regex.append("|)");
+ // :operations prefix optional
+
+ regex.append("operations\"");
+ regex.append(".*:");
+ regex.append(".*\\{");
+
+ regex.append(".*\"" + moduleName);
+ regex.append(":");
+ regex.append(rpcName + "\"");
+ regex.append(".*\\[");
+ regex.append(".*null");
+ regex.append(".*\\]");
+
+ regex.append(".*\\}");
+ regex.append(".*\\}");
+
+ regex.append(".*");
+ regex.append("$");
+ Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
+ return ptrn.matcher(searchIn);
+
+ }
+
+ private Matcher validateOperationsResponseXml(String searchIn, String rpcName, String namespace) {
+ StringBuilder regex = new StringBuilder();
+
+ regex.append("^");
+
+ regex.append(".*<operations");
+ regex.append(".*xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"");
+ regex.append(".*>");
+
+ regex.append(".*<");
+ regex.append(".*" + rpcName);
+ regex.append(".*" + namespace);
+ regex.append(".*/");
+ regex.append(".*>");
+
+ regex.append(".*</operations.*");
+ regex.append(".*>");
+
+ regex.append(".*");
+ regex.append("$");
+ Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL);
+ return ptrn.matcher(searchIn);
+ }
+
+ // /restconf/modules/pathToMountPoint/yang-ext:mount
+ @Test
+ public void getModulesBehindMountPoint() throws FileNotFoundException, UnsupportedEncodingException {
+ ControllerContext controllerContext = ControllerContext.getInstance();
+ controllerContext.setGlobalSchema(schemaContextModules);
+
+ MountInstance mountInstance = mock(MountInstance.class);
+ when(mountInstance.getSchemaContext()).thenReturn(schemaContextBehindMountPoint);
+ MountService mockMountService = mock(MountService.class);
+ when(mockMountService.getMountPoint(any(InstanceIdentifier.class))).thenReturn(mountInstance);
+
+ controllerContext.setMountService(mockMountService);
+
+ String uri = createUri("/modules/", "ietf-interfaces:interfaces/interface/0/yang-ext:mount/");
+
+ Response response = target(uri).request("application/yang.api+json").get();