2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.restconf.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.doThrow;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
17 import com.google.common.util.concurrent.CheckedFuture;
18 import java.io.FileNotFoundException;
19 import java.io.UnsupportedEncodingException;
21 import javax.ws.rs.core.Application;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.glassfish.jersey.server.ResourceConfig;
25 import org.glassfish.jersey.test.JerseyTest;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
29 import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
30 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
31 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
32 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
33 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
35 import org.opendaylight.yangtools.yang.model.api.Module;
36 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
38 public class RestDeleteOperationTest extends JerseyTest {
40 private static ControllerContext controllerContext;
41 private static BrokerFacade brokerFacade;
42 private static RestconfImpl restconfImpl;
45 public static void init() throws FileNotFoundException {
46 Set<Module> allModules = TestUtils.loadModulesFrom("/test-config-data/yang1");
47 assertNotNull(allModules);
48 SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
49 controllerContext = ControllerContext.getInstance();
50 controllerContext.setSchemas(schemaContext);
51 brokerFacade = mock(BrokerFacade.class);
52 restconfImpl = RestconfImpl.getInstance();
53 restconfImpl.setBroker(brokerFacade);
54 restconfImpl.setControllerContext(controllerContext);
58 protected Application configure() {
59 /* enable/disable Jersey logs to console */
60 // enable(TestProperties.LOG_TRAFFIC);
61 // enable(TestProperties.DUMP_ENTITY);
62 // enable(TestProperties.RECORD_LOG_LEVEL);
63 // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
64 ResourceConfig resourceConfig = new ResourceConfig();
65 resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE,
66 XmlToCompositeNodeProvider.INSTANCE);
67 return resourceConfig;
71 public void deleteConfigStatusCodes() throws UnsupportedEncodingException {
72 String uri = "/config/test-interface:interfaces";
73 when(brokerFacade.commitConfigurationDataDelete(any(YangInstanceIdentifier.class))).thenReturn(
74 mock(CheckedFuture.class));
75 Response response = target(uri).request(MediaType.APPLICATION_XML).delete();
76 assertEquals(200, response.getStatus());
78 doThrow(RestconfDocumentedException.class).when(brokerFacade).commitConfigurationDataDelete(
79 any(YangInstanceIdentifier.class));
80 response = target(uri).request(MediaType.APPLICATION_XML).delete();
81 assertEquals(500, response.getStatus());