X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestGetOperationTest.java;h=eb7ea71bf4c65bee9336a2561e7470c16aabfc0f;hb=a59286ee063c90817958e9cef4836e15aec3c7a6;hp=8e1121a562c964debf3da74c870a8801a763e6b3;hpb=919145b1bf7d68e436efa9b22c174965005a174a;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java index 8e1121a562..eb7ea71bf4 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java @@ -18,7 +18,6 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.base.Optional; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; @@ -91,6 +90,7 @@ public class RestGetOperationTest extends JerseyTest { private static RestconfImpl restconfImpl; private static SchemaContext schemaContextYangsIetf; private static SchemaContext schemaContextTestModule; + @SuppressWarnings("rawtypes") private static NormalizedNode answerFromGet; private static SchemaContext schemaContextModules; @@ -163,6 +163,7 @@ public class RestGetOperationTest extends JerseyTest { /** * MountPoint test. URI represents mount point. */ + @SuppressWarnings("unchecked") @Test public void getDataWithUrlMountPoint() throws UnsupportedEncodingException, URISyntaxException, ParseException { when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), any(YangInstanceIdentifier.class))).thenReturn( @@ -187,7 +188,7 @@ public class RestGetOperationTest extends JerseyTest { * Slashes in URI behind mount point. lst1 element with key GigabitEthernet0%2F0%2F0%2F0 (GigabitEthernet0/0/0/0) is * requested via GET HTTP operation. It is tested whether %2F character is replaced with simple / in * InstanceIdentifier parameter in method - * {@link BrokerFacade#readConfigurationDataBehindMountPoint(MountInstance, YangInstanceIdentifier)} which is called in + * {@link BrokerFacade#readConfigurationData(DOMMountPoint, YangInstanceIdentifier)} which is called in * method {@link RestconfImpl#readConfigurationData} * * @throws ParseException @@ -311,7 +312,6 @@ public class RestGetOperationTest extends JerseyTest { // /operations @Test - @Ignore // FIXME restconf-netconf yang schema has to be updated for operations container public void getOperationsTest() throws FileNotFoundException, UnsupportedEncodingException { setControllerContext(schemaContextModules); @@ -337,32 +337,26 @@ public class RestGetOperationTest extends JerseyTest { } private void validateOperationsResponseXml(final Document responseDoc, final SchemaContext schemaContext) { + final Element operationsElem = responseDoc.getDocumentElement(); assertEquals(RESTCONF_NS, operationsElem.getNamespaceURI()); assertEquals("operations", operationsElem.getLocalName()); - - final HashSet foundOperations = new HashSet<>(); - final NodeList operationsList = operationsElem.getChildNodes(); - for(int i = 0;i < operationsList.getLength();i++) { - final org.w3c.dom.Node operation = operationsList.item(i); + final HashSet foundOperations = new HashSet<>(); - final String namespace = operation.getNamespaceURI(); - final String name = operation.getLocalName(); - final QName opQName = QName.create(URI.create(namespace), null, name); - foundOperations.add(opQName); + for (int i = 0; i < operationsList.getLength(); i++) { + final org.w3c.dom.Node operation = operationsList.item(i); + foundOperations.add(operation.getLocalName()); } - for(final RpcDefinition schemaOp : schemaContext.getOperations()) { - assertTrue(foundOperations.contains(schemaOp.getQName().withoutRevision())); + for (final RpcDefinition schemaOp : schemaContext.getOperations()) { + assertTrue(foundOperations.contains(schemaOp.getQName().getLocalName())); } - } // /operations/pathToMountPoint/yang-ext:mount @Test - @Ignore // FIXME fix the way to provide operations overview functionality asap public void getOperationsBehindMountPointTest() throws FileNotFoundException, UnsupportedEncodingException { setControllerContext(schemaContextModules); @@ -393,33 +387,7 @@ public class RestGetOperationTest extends JerseyTest { private Matcher validateOperationsResponseJson(final String searchIn, final String rpcName, final String moduleName) { final 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("$"); + regex.append(".*\"" + rpcName + "\""); final Pattern ptrn = Pattern.compile(regex.toString(), Pattern.DOTALL); return ptrn.matcher(searchIn); @@ -628,13 +596,6 @@ public class RestGetOperationTest extends JerseyTest { } - private void prepareMockForModulesTest(final ControllerContext mockedControllerContext) - throws FileNotFoundException { - final SchemaContext schemaContext = TestUtils.loadSchemaContext("/modules"); - mockedControllerContext.setGlobalSchema(schemaContext); - // when(mockedControllerContext.getGlobalSchema()).thenReturn(schemaContext); - } - private int get(final String uri, final String mediaType) { return target(uri).request(mediaType).get().getStatus(); } @@ -646,6 +607,7 @@ public class RestGetOperationTest extends JerseyTest { type string; } */ + @SuppressWarnings("rawtypes") private NormalizedNode prepareCnDataForMountPointTest(final boolean wrapToCont) throws URISyntaxException, ParseException { final String testModuleDate = "2014-01-09"; final ContainerNode contChild = Builders @@ -665,14 +627,17 @@ public class RestGetOperationTest extends JerseyTest { } + @SuppressWarnings("unchecked") private void mockReadOperationalDataMethod() { when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(answerFromGet); } + @SuppressWarnings("unchecked") private void mockReadConfigurationDataMethod() { when(brokerFacade.readConfigurationData(any(YangInstanceIdentifier.class))).thenReturn(answerFromGet); } + @SuppressWarnings("rawtypes") private NormalizedNode prepareCnDataForSlashesBehindMountPointTest() throws ParseException { return ImmutableMapEntryNodeBuilder .create() @@ -746,6 +711,7 @@ public class RestGetOperationTest extends JerseyTest { getDataWithInvalidDepthParameterTest(mockInfo); } + @SuppressWarnings({"rawtypes", "unchecked"}) private void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) { try { final QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont"); @@ -760,6 +726,7 @@ public class RestGetOperationTest extends JerseyTest { } } + @SuppressWarnings("unused") private void verifyXMLResponse(final Response response, final NodeData nodeData) { final Document doc = response.readEntity(Document.class); // Document doc = TestUtils.loadDocumentFrom((InputStream) response.getEntity()); @@ -812,28 +779,4 @@ public class RestGetOperationTest extends JerseyTest { } } - private NodeData expectContainer(final String name, final NodeData... childData) { - return new NodeData(name, Lists.newArrayList(childData)); - } - - private NodeData expectEmptyContainer(final String name) { - return new NodeData(name, null); - } - - private NodeData expectLeaf(final String name, final Object value) { - return new NodeData(name, value); - } - - private QName toNestedQName(final String localName) { - return QName.create("urn:nested:module", "2014-06-3", localName); - } - - private NodeData toCompositeNodeData(final QName key, final NodeData... childData) { - return new NodeData(key, Lists.newArrayList(childData)); - } - - private NodeData toSimpleNodeData(final QName key, final Object value) { - return new NodeData(key, value); - } - }