Add kubevirt API config service, expose it via REST API and CLI

Change-Id: I45a867ad54622656475758e7b4af38c19e551790
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java
new file mode 100644
index 0000000..773401e
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigCodecTest.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnode.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.codec.impl.CodecManager;
+import org.onosproject.core.CoreService;
+import org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfig;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.Scheme.HTTPS;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.State.CONNECTED;
+import static org.onosproject.kubevirtnode.codec.KubevirtApiConfigJsonMatcher.matchesKubevirtApiConfig;
+import static org.onosproject.net.NetTestTools.APP_ID;
+
+/**
+ * Unit tests for KubeVirt API config codec.
+ */
+public class KubevirtApiConfigCodecTest {
+
+    MockCodecContext context;
+
+    JsonCodec<KubevirtApiConfig> kubevirtApiConfigCodec;
+
+    final CoreService mockCoreService = createMock(CoreService.class);
+    private static final String REST_APP_ID = "org.onosproject.rest";
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+        context = new MockCodecContext();
+        kubevirtApiConfigCodec = new KubevirtApiConfigCodec();
+
+        assertThat(kubevirtApiConfigCodec, notNullValue());
+
+        expect(mockCoreService.registerApplication(REST_APP_ID))
+                .andReturn(APP_ID).anyTimes();
+        replay(mockCoreService);
+        context.registerService(CoreService.class, mockCoreService);
+    }
+
+    /**
+     * Tests the KubeVirt API config encoding.
+     */
+    @Test
+    public void testKubevirtApiConfigEncode() {
+        KubevirtApiConfig config = DefaultKubevirtApiConfig.builder()
+                .scheme(HTTPS)
+                .ipAddress(IpAddress.valueOf("10.10.10.23"))
+                .port(6443)
+                .state(CONNECTED)
+                .token("token")
+                .caCertData("caCertData")
+                .clientCertData("clientCertData")
+                .clientKeyData("clientKeyData")
+                .build();
+        ObjectNode configJson = kubevirtApiConfigCodec.encode(config, context);
+        assertThat(configJson, matchesKubevirtApiConfig(config));
+    }
+
+    /**
+     * Tests the KubeVirt API config decoding.
+     *
+     * @throws IOException IO exception
+     */
+    @Test
+    public void testKubevirtApiConfigDecode() throws IOException {
+        KubevirtApiConfig config = getKubevirtApiConfig("KubevirtApiConfig.json");
+
+        assertEquals("HTTPS", config.scheme().name());
+        assertEquals("10.134.34.223", config.ipAddress().toString());
+        assertEquals(6443, config.port());
+        assertEquals("token", config.token());
+        assertEquals("caCertData", config.caCertData());
+        assertEquals("clientCertData", config.clientCertData());
+        assertEquals("clientKeyData", config.clientKeyData());
+    }
+
+    private KubevirtApiConfig getKubevirtApiConfig(String resourceName) throws IOException {
+        InputStream jsonStream = KubevirtNodeCodecTest.class.getResourceAsStream(resourceName);
+        JsonNode json = context.mapper().readTree(jsonStream);
+        assertThat(json, notNullValue());
+        KubevirtApiConfig config = kubevirtApiConfigCodec.decode((ObjectNode) json, context);
+        assertThat(config, notNullValue());
+        return config;
+    }
+
+    private class MockCodecContext implements CodecContext {
+        private final ObjectMapper mapper = new ObjectMapper();
+        private final CodecManager manager = new CodecManager();
+        private final Map<Class<?>, Object> services = new HashMap<>();
+
+        /**
+         * Constructs a new mock codec context.
+         */
+        public MockCodecContext() {
+            manager.activate();
+        }
+
+        @Override
+        public ObjectMapper mapper() {
+            return mapper;
+        }
+
+        @Override
+        @SuppressWarnings("unchecked")
+        public <T> JsonCodec<T> codec(Class<T> entityClass) {
+            if (entityClass == KubevirtApiConfig.class) {
+                return (JsonCodec<T>) kubevirtApiConfigCodec;
+            }
+            return manager.getCodec(entityClass);
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public <T> T getService(Class<T> serviceClass) {
+            return (T) services.get(serviceClass);
+        }
+
+        // for registering mock services
+        public <T> void registerService(Class<T> serviceClass, T impl) {
+            services.put(serviceClass, impl);
+        }
+    }
+}
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigJsonMatcher.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigJsonMatcher.java
new file mode 100644
index 0000000..17df9bc
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/codec/KubevirtApiConfigJsonMatcher.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnode.codec;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfig;
+
+/**
+ * Hamcrest matcher for KubeVirt API config.
+ */
+public final class KubevirtApiConfigJsonMatcher extends TypeSafeDiagnosingMatcher<JsonNode> {
+
+    private final KubevirtApiConfig kubevirtApiConfig;
+
+    private static final String SCHEME = "scheme";
+    private static final String IP_ADDRESS = "ipAddress";
+    private static final String PORT = "port";
+    private static final String STATE = "state";
+    private static final String TOKEN = "token";
+    private static final String CA_CERT_DATA = "caCertData";
+    private static final String CLIENT_CERT_DATA = "clientCertData";
+    private static final String CLIENT_KEY_DATA = "clientKeyData";
+
+    private KubevirtApiConfigJsonMatcher(KubevirtApiConfig kubevirtApiConfig) {
+        this.kubevirtApiConfig = kubevirtApiConfig;
+    }
+
+    @Override
+    protected boolean matchesSafely(JsonNode jsonNode, Description description) {
+        // check scheme
+        String jsonScheme = jsonNode.get(SCHEME).asText();
+        String scheme = kubevirtApiConfig.scheme().name();
+        if (!jsonScheme.equals(scheme)) {
+            description.appendText("scheme was " + jsonScheme);
+            return false;
+        }
+
+        // check IP address
+        String jsonIpAddress = jsonNode.get(IP_ADDRESS).asText();
+        String ipAddress = kubevirtApiConfig.ipAddress().toString();
+        if (!jsonIpAddress.equals(ipAddress)) {
+            description.appendText("ipAddress was " + jsonIpAddress);
+            return false;
+        }
+
+        // check port
+        int jsonPort = jsonNode.get(PORT).asInt();
+        int port = kubevirtApiConfig.port();
+        if (jsonPort != port) {
+            description.appendText("port was " + jsonPort);
+            return false;
+        }
+
+        // check state
+        JsonNode jsonState = jsonNode.get(STATE);
+        String state = kubevirtApiConfig.state().name();
+        if (jsonState != null) {
+            if (!jsonState.asText().equals(state)) {
+                description.appendText("state was " + jsonState);
+                return false;
+            }
+        }
+
+        // check token
+        JsonNode jsonToken = jsonNode.get(TOKEN);
+        String token = kubevirtApiConfig.token();
+        if (jsonToken != null) {
+            if (!jsonToken.asText().equals(token)) {
+                description.appendText("token was " + jsonToken);
+                return false;
+            }
+        }
+
+        // check caCertData
+        JsonNode jsonCaCertData = jsonNode.get(CA_CERT_DATA);
+        String caCertData = kubevirtApiConfig.caCertData();
+        if (jsonCaCertData != null) {
+            if (!jsonCaCertData.asText().equals(caCertData)) {
+                description.appendText("caCertData was " + jsonCaCertData);
+                return false;
+            }
+        }
+
+        // check clientCertData
+        JsonNode jsonClientCertData = jsonNode.get(CLIENT_CERT_DATA);
+        String clientCertData = kubevirtApiConfig.clientCertData();
+
+        if (jsonClientCertData != null) {
+            if (!jsonClientCertData.asText().equals(clientCertData)) {
+                description.appendText("clientCertData was " + jsonClientCertData);
+                return false;
+            }
+        }
+
+        // check clientKeyData
+        JsonNode jsonClientKeyData = jsonNode.get(CLIENT_KEY_DATA);
+        String clientKeyData = kubevirtApiConfig.clientKeyData();
+
+        if (jsonClientKeyData != null) {
+            if (!jsonClientKeyData.asText().equals(clientKeyData)) {
+                description.appendText("clientKeyData was " + jsonClientKeyData);
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText(kubevirtApiConfig.toString());
+    }
+
+    /**
+     * Factory to allocate an kubevirtApiConfig matcher.
+     *
+     * @param config kubevirtApiConfig object we are looking for
+     * @return matcher
+     */
+    public static KubevirtApiConfigJsonMatcher matchesKubevirtApiConfig(KubevirtApiConfig config) {
+        return new KubevirtApiConfigJsonMatcher(config);
+    }
+}
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java
new file mode 100644
index 0000000..0e5db34
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/impl/KubevirtApiConfigManagerTest.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnode.impl;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.MoreExecutors;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onlab.packet.IpAddress;
+import org.onosproject.cluster.ClusterServiceAdapter;
+import org.onosproject.cluster.LeadershipServiceAdapter;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreServiceAdapter;
+import org.onosproject.core.DefaultApplicationId;
+import org.onosproject.event.Event;
+import org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfigEvent;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfigListener;
+import org.onosproject.store.service.TestStorageService;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.State.DISCONNECTED;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfigEvent.Type.KUBEVIRT_API_CONFIG_CREATED;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfigEvent.Type.KUBEVIRT_API_CONFIG_REMOVED;
+import static org.onosproject.kubevirtnode.util.KubevirtNodeUtil.endpoint;
+
+
+/**
+ * Unit tests for KubeVirt API config manager.
+ */
+public class KubevirtApiConfigManagerTest {
+
+    private static final ApplicationId TEST_APP_ID = new DefaultApplicationId(1, "test");
+
+    private static final String ERR_SIZE = "Number of configs did not match";
+    private static final String ERR_NOT_MATCH = "Config did not match";
+    private static final String ERR_NOT_FOUND = "Config did not exist";
+
+    private KubevirtApiConfig apiConfig1;
+    private KubevirtApiConfig apiConfig2;
+
+    private final TestKubevirtApiConfigListener testListener = new TestKubevirtApiConfigListener();
+
+    private KubevirtApiConfigManager target;
+    private DistributedKubevirtApiConfigStore configStore;
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+        apiConfig1 = DefaultKubevirtApiConfig.builder()
+                .scheme(KubevirtApiConfig.Scheme.HTTP)
+                .ipAddress(IpAddress.valueOf("10.10.10.2"))
+                .port(6443)
+                .state(DISCONNECTED)
+                .build();
+        apiConfig2 = DefaultKubevirtApiConfig.builder()
+                .scheme(KubevirtApiConfig.Scheme.HTTP)
+                .ipAddress(IpAddress.valueOf("10.10.10.3"))
+                .port(6443)
+                .state(DISCONNECTED)
+                .build();
+
+        configStore = new DistributedKubevirtApiConfigStore();
+        TestUtils.setField(configStore, "coreService", new TestCoreService());
+        TestUtils.setField(configStore, "storageService", new TestStorageService());
+        TestUtils.setField(configStore, "eventExecutor", MoreExecutors.newDirectExecutorService());
+        configStore.activate();
+
+        target = new KubevirtApiConfigManager();
+        target.storageService = new TestStorageService();
+        target.coreService = new TestCoreService();
+        target.clusterService = new TestClusterService();
+        target.leadershipService = new TestLeadershipService();
+        target.configStore = configStore;
+        target.addListener(testListener);
+        target.activate();
+        testListener.events.clear();
+    }
+
+    /**
+     * Clean up unit test.
+     */
+    @After
+    public void tearDown() {
+        target.removeListener(testListener);
+        target.deactivate();
+        configStore.deactivate();
+        configStore = null;
+        target = null;
+    }
+
+    /**
+     * Checks if creating and removing a config work well with proper events.
+     */
+    @Test
+    public void testCreateAndRemoveConfig() {
+        target.createApiConfig(apiConfig1);
+        assertNotNull(target.apiConfig());
+
+        target.removeApiConfig(endpoint(apiConfig1));
+        assertNull(target.apiConfig());
+
+        validateEvents(KUBEVIRT_API_CONFIG_CREATED, KUBEVIRT_API_CONFIG_REMOVED);
+    }
+
+    /**
+     * Checks if the stored config is unique or not.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testConfigUniqueness() {
+        target.createApiConfig(apiConfig1);
+        target.createApiConfig(apiConfig2);
+        validateEvents(KUBEVIRT_API_CONFIG_CREATED);
+    }
+
+    /**
+     * Checks if removing null config fails with proper exception.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testRemoveNullConfig() {
+        target.removeApiConfig(null);
+    }
+
+    private void validateEvents(Enum... types) {
+        int i = 0;
+        assertEquals("Number of events did not match", types.length, testListener.events.size());
+        for (Event event : testListener.events) {
+            assertEquals("Incorrect event received", types[i], event.type());
+            i++;
+        }
+        testListener.events.clear();
+    }
+
+    private static class TestKubevirtApiConfigListener implements KubevirtApiConfigListener {
+        private List<KubevirtApiConfigEvent> events = Lists.newArrayList();
+
+        @Override
+        public void event(KubevirtApiConfigEvent event) {
+            events.add(event);
+        }
+    }
+
+    private static class TestCoreService extends CoreServiceAdapter {
+        @Override
+        public ApplicationId registerApplication(String name) {
+            return TEST_APP_ID;
+        }
+    }
+
+    private class TestClusterService extends ClusterServiceAdapter {
+
+    }
+
+    private static class TestLeadershipService extends LeadershipServiceAdapter {
+
+    }
+}
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java
new file mode 100644
index 0000000..e6d1034
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtApiConfigWebResourceTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.kubevirtnode.web;
+
+import org.glassfish.jersey.server.ResourceConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.osgi.ServiceDirectory;
+import org.onlab.osgi.TestServiceDirectory;
+import org.onlab.packet.IpAddress;
+import org.onosproject.codec.CodecService;
+import org.onosproject.codec.impl.CodecManager;
+import org.onosproject.kubevirtnode.api.DefaultKubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfig;
+import org.onosproject.kubevirtnode.api.KubevirtApiConfigAdminService;
+import org.onosproject.kubevirtnode.codec.KubevirtApiConfigCodec;
+import org.onosproject.rest.resources.ResourceTest;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.InputStream;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.Scheme.HTTPS;
+import static org.onosproject.kubevirtnode.api.KubevirtApiConfig.State.DISCONNECTED;
+
+/**
+ * Unit test for KubeVirt node REST API.
+ */
+public class KubevirtApiConfigWebResourceTest extends ResourceTest {
+
+    final KubevirtApiConfigAdminService mockConfigAdminService =
+            createMock(KubevirtApiConfigAdminService.class);
+    private static final String PATH = "api-config";
+
+    private KubevirtApiConfig kubevirtApiConfig;
+
+    /**
+     * Constructs a KubeVirt API config resource test instance.
+     */
+    public KubevirtApiConfigWebResourceTest() {
+        super(ResourceConfig.forApplicationClass(KubevirtNodeWebApplication.class));
+    }
+
+    /**
+     * Sets up the global values for all the tests.
+     */
+    @Before
+    public void setUpTest() {
+        final CodecManager codecService = new CodecManager();
+        codecService.activate();
+        codecService.registerCodec(KubevirtApiConfig.class, new KubevirtApiConfigCodec());
+        ServiceDirectory testDirectory =
+                new TestServiceDirectory()
+                .add(KubevirtApiConfigAdminService.class, mockConfigAdminService)
+                .add(CodecService.class, codecService);
+        setServiceDirectory(testDirectory);
+
+        kubevirtApiConfig = DefaultKubevirtApiConfig.builder()
+                .scheme(HTTPS)
+                .ipAddress(IpAddress.valueOf("10.134.34.223"))
+                .port(6443)
+                .state(DISCONNECTED)
+                .token("tokenMod")
+                .caCertData("caCertData")
+                .clientCertData("clientCertData")
+                .clientKeyData("clientKeyData")
+                .build();
+    }
+
+    /**
+     * Tests the results of the REST API POST method with creating new configs operation.
+     */
+    @Test
+    public void testCreateConfigWithCreateOperation() {
+        mockConfigAdminService.createApiConfig(anyObject());
+        replay(mockConfigAdminService);
+
+        final WebTarget wt = target();
+        InputStream jsonStream = KubevirtApiConfigWebResourceTest.class
+                .getResourceAsStream("kubevirt-api-config.json");
+        Response response = wt.path(PATH).request(MediaType.APPLICATION_JSON_TYPE)
+                .post(Entity.json(jsonStream));
+        final int status = response.getStatus();
+
+        assertThat(status, is(201));
+
+        verify(mockConfigAdminService);
+    }
+
+    /**
+     * Tests the results of the REST API POST method without creating new configs operation.
+     */
+    @Test
+    public void testCreateConfigWithNullConfig() {
+        mockConfigAdminService.createApiConfig(null);
+        replay(mockConfigAdminService);
+
+        final WebTarget wt = target();
+        InputStream jsonStream = KubevirtApiConfigWebResourceTest.class
+                .getResourceAsStream("kubevirt-api-config.json");
+        Response response = wt.path(PATH).request(MediaType.APPLICATION_JSON_TYPE)
+                .post(Entity.json(jsonStream));
+        final int status = response.getStatus();
+
+        assertThat(status, is(500));
+    }
+
+    /**
+     * Tests the results of the REST API DELETE method with deleting the configs.
+     */
+    @Test
+    public void testDeleteConfigsWithDeletionOperation() {
+        expect(mockConfigAdminService.apiConfig())
+                .andReturn(kubevirtApiConfig).once();
+        expect(mockConfigAdminService.removeApiConfig(anyString()))
+                .andReturn(kubevirtApiConfig).once();
+        replay(mockConfigAdminService);
+
+        String location = PATH + "/https://10.134.34.223:6443";
+
+        final WebTarget wt = target();
+        Response response = wt.path(location).request(
+                MediaType.APPLICATION_JSON_TYPE).delete();
+
+        final int status = response.getStatus();
+
+        assertThat(status, is(204));
+
+        verify(mockConfigAdminService);
+    }
+
+    /**
+     * Tests the results of the REST API DELETE method without deleting the configs.
+     */
+    @Test
+    public void testDeleteConfigsWithoutDeletionOperation() {
+        expect(mockConfigAdminService.apiConfig()).andReturn(null).once();
+        replay(mockConfigAdminService);
+
+        String location = PATH + "/https://test:8663";
+
+        final WebTarget wt = target();
+        Response response = wt.path(location).request(
+                MediaType.APPLICATION_JSON_TYPE).delete();
+
+        final int status = response.getStatus();
+
+        assertThat(status, is(304));
+
+        verify(mockConfigAdminService);
+    }
+}
diff --git a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtNodeWebResourceTest.java b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtNodeWebResourceTest.java
index 7d15e90..cf52f00 100644
--- a/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtNodeWebResourceTest.java
+++ b/apps/kubevirt-node/app/src/test/java/org/onosproject/kubevirtnode/web/KubevirtNodeWebResourceTest.java
@@ -35,7 +35,6 @@
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-
 import java.io.InputStream;
 
 import static org.easymock.EasyMock.anyObject;
@@ -53,7 +52,7 @@
 public class KubevirtNodeWebResourceTest extends ResourceTest {
 
     final KubevirtNodeAdminService mockKubevirtNodeAdminService = createMock(KubevirtNodeAdminService.class);
-    private static final String NODE_PATH = "configure/node";
+    private static final String PATH = "node";
 
     private KubevirtNode kubevirtNode;
 
@@ -101,7 +100,7 @@
         InputStream jsonStream = KubevirtNodeWebResourceTest.class
                 .getResourceAsStream("kubevirt-worker-node.json");
 
-        Response response = wt.path(NODE_PATH).request(MediaType.APPLICATION_JSON_TYPE)
+        Response response = wt.path(PATH).request(MediaType.APPLICATION_JSON_TYPE)
                 .post(Entity.json(jsonStream));
         final int status = response.getStatus();
 
@@ -123,7 +122,7 @@
         InputStream jsonStream = KubevirtNodeWebResourceTest.class
                 .getResourceAsStream("kubevirt-worker-node.json");
 
-        Response response = wt.path(NODE_PATH).request(MediaType.APPLICATION_JSON_TYPE)
+        Response response = wt.path(PATH).request(MediaType.APPLICATION_JSON_TYPE)
                 .put(Entity.json(jsonStream));
         final int status = response.getStatus();
 
@@ -144,7 +143,7 @@
         InputStream jsonStream = KubevirtNodeWebResourceTest.class
                 .getResourceAsStream("kubevirt-worker-node.json");
 
-        Response response = wt.path(NODE_PATH).request(MediaType.APPLICATION_JSON_TYPE)
+        Response response = wt.path(PATH).request(MediaType.APPLICATION_JSON_TYPE)
                 .put(Entity.json(jsonStream));
         final int status = response.getStatus();
 
@@ -162,7 +161,7 @@
         expect(mockKubevirtNodeAdminService.removeNode(anyString())).andReturn(kubevirtNode).once();
         replay(mockKubevirtNodeAdminService);
 
-        String location = NODE_PATH + "/worker-node";
+        String location = PATH + "/worker-node";
 
         final WebTarget wt = target();
         Response response = wt.path(location).request(
@@ -183,7 +182,7 @@
         expect(mockKubevirtNodeAdminService.node(anyString())).andReturn(null).once();
         replay(mockKubevirtNodeAdminService);
 
-        String location = NODE_PATH + "/worker-node";
+        String location = PATH + "/worker-node";
 
         final WebTarget wt = target();
         Response response = wt.path(location).request(
diff --git a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json
new file mode 100644
index 0000000..f706cc3
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/codec/KubevirtApiConfig.json
@@ -0,0 +1,9 @@
+{
+  "scheme" : "HTTPS",
+  "ipAddress" : "10.134.34.223",
+  "port" : 6443,
+  "token": "token",
+  "caCertData": "caCertData",
+  "clientCertData": "clientCertData",
+  "clientKeyData": "clientKeyData"
+}
\ No newline at end of file
diff --git a/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json
new file mode 100644
index 0000000..f706cc3
--- /dev/null
+++ b/apps/kubevirt-node/app/src/test/resources/org/onosproject/kubevirtnode/web/kubevirt-api-config.json
@@ -0,0 +1,9 @@
+{
+  "scheme" : "HTTPS",
+  "ipAddress" : "10.134.34.223",
+  "port" : 6443,
+  "token": "token",
+  "caCertData": "caCertData",
+  "clientCertData": "clientCertData",
+  "clientKeyData": "clientKeyData"
+}
\ No newline at end of file