1 package org.opendaylight.controller.sal.restconf.impl.test;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.mockito.Matchers.any;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
8 import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri;
10 import java.io.FileNotFoundException;
11 import java.io.UnsupportedEncodingException;
13 import java.util.concurrent.Future;
14 import java.util.logging.Level;
16 import javax.ws.rs.core.Application;
17 import javax.ws.rs.core.MediaType;
18 import javax.ws.rs.core.Response;
20 import org.glassfish.jersey.server.ResourceConfig;
21 import org.glassfish.jersey.test.JerseyTest;
22 import org.glassfish.jersey.test.TestProperties;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
26 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
27 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
28 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
29 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
30 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
32 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.model.api.Module;
34 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
36 public class RestDeleteOperationTest extends JerseyTest {
38 private static ControllerContext controllerContext;
39 private static BrokerFacade brokerFacade;
40 private static RestconfImpl restconfImpl;
41 private static final MediaType MEDIA_TYPE_DRAFT02 = new MediaType("application", "yang.data+xml");
44 public static void init() throws FileNotFoundException {
45 Set<Module> allModules = TestUtils.loadModulesFrom("/test-config-data/yang1");
46 assertNotNull(allModules);
47 SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
48 controllerContext = ControllerContext.getInstance();
49 controllerContext.setSchemas(schemaContext);
50 brokerFacade = mock(BrokerFacade.class);
51 restconfImpl = RestconfImpl.getInstance();
52 restconfImpl.setBroker(brokerFacade);
53 restconfImpl.setControllerContext(controllerContext);
57 protected Application configure() {
58 /* enable/disable Jersey logs to console */
60 * enable(TestProperties.LOG_TRAFFIC);
62 enable(TestProperties.DUMP_ENTITY);
63 enable(TestProperties.RECORD_LOG_LEVEL);
64 set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
66 ResourceConfig resourceConfig = new ResourceConfig();
67 resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE,
68 XmlToCompositeNodeProvider.INSTANCE);
69 return resourceConfig;
73 public void testDeleteConfigurationData() throws UnsupportedEncodingException, FileNotFoundException {
74 String uri2 = createUri("/config/", "test-interface:interfaces");
76 RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(
77 TransactionStatus.COMMITED).build();
78 Future<RpcResult<TransactionStatus>> dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build();
79 when(brokerFacade.commitConfigurationDataDelete(any(InstanceIdentifier.class))).thenReturn(dummyFuture);
81 Response response = target(uri2).request(MEDIA_TYPE_DRAFT02).delete();
82 assertEquals(200, response.getStatus());
84 rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(TransactionStatus.FAILED).build();
85 dummyFuture = DummyFuture.builder().rpcResult(rpcResult).build();
87 when(brokerFacade.commitConfigurationDataDelete(any(InstanceIdentifier.class))).thenReturn(dummyFuture);
89 response = target(uri2).request(MEDIA_TYPE_DRAFT02).delete();
90 assertEquals(500, response.getStatus());