Add keystone and neutron config classes and codec with unit tests
Change-Id: Ia89f5be9bac88927a383d56d56413ba23e3e5eb3
diff --git a/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultKeystoneConfigTest.java b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultKeystoneConfigTest.java
new file mode 100644
index 0000000..348695b
--- /dev/null
+++ b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultKeystoneConfigTest.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2018-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.openstacknode.api;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.openstacknode.api.OpenstackAuth.Perspective.PUBLIC;
+import static org.onosproject.openstacknode.api.OpenstackAuth.Protocol.HTTP;
+
+/**
+ * Unit tests for DefaultKeystoneConfig.
+ */
+public final class DefaultKeystoneConfigTest {
+
+ private static final String ENDPOINT_1 = "192.168.0.10:35357/v2.0";
+ private static final String ENDPOINT_2 = "192.168.0.11:80/v3";
+
+ private static final String USERNAME = "admin";
+ private static final String PASSWORD = "nova";
+ private static final String PROJECT = "admin";
+ private static final String VERSION_2 = "v2.0";
+ private static final String VERSION_3 = "v3";
+
+ private static final OpenstackAuth AUTHENTICATION_1 = createAuthv2();
+ private static final OpenstackAuth AUTHENTICATION_2 = createAuthv3();
+
+ private KeystoneConfig config1;
+ private KeystoneConfig sameAsConfig1;
+ private KeystoneConfig config2;
+
+ private static OpenstackAuth createAuthv2() {
+ return DefaultOpenstackAuth.builder()
+ .username(USERNAME)
+ .password(PASSWORD)
+ .project(PROJECT)
+ .version(VERSION_2)
+ .perspective(PUBLIC)
+ .protocol(HTTP)
+ .build();
+ }
+
+ private static OpenstackAuth createAuthv3() {
+ return DefaultOpenstackAuth.builder()
+ .username(USERNAME)
+ .password(PASSWORD)
+ .project(PROJECT)
+ .version(VERSION_3)
+ .perspective(PUBLIC)
+ .protocol(HTTP)
+ .build();
+ }
+
+ /**
+ * Tests class immutability.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultKeystoneConfig.class);
+ }
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+ config1 = DefaultKeystoneConfig.builder()
+ .endpoint(ENDPOINT_1)
+ .authentication(AUTHENTICATION_1)
+ .build();
+
+ sameAsConfig1 = DefaultKeystoneConfig.builder()
+ .endpoint(ENDPOINT_1)
+ .authentication(AUTHENTICATION_1)
+ .build();
+
+ config2 = DefaultKeystoneConfig.builder()
+ .endpoint(ENDPOINT_2)
+ .authentication(AUTHENTICATION_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(config1, sameAsConfig1)
+ .addEqualityGroup(config2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ KeystoneConfig config = config1;
+
+ assertEquals(config.endpoint(), ENDPOINT_1);
+ assertEquals(config.authentication(), AUTHENTICATION_1);
+ }
+}
diff --git a/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultNeutronConfigTest.java b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultNeutronConfigTest.java
new file mode 100644
index 0000000..63c3833
--- /dev/null
+++ b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/DefaultNeutronConfigTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2018-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.openstacknode.api;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+
+/**
+ * Unit tests for DefaultNeutronConfig.
+ */
+public class DefaultNeutronConfigTest {
+
+ private static final boolean USE_METADATA_PROXY_1 = true;
+ private static final boolean USE_METADATA_PROXY_2 = false;
+
+ private static final String METADATA_PROXY_SECRET_1 = "onos";
+ private static final String METADATA_PROXY_SECRET_2 = "cord";
+
+ private NeutronConfig config1;
+ private NeutronConfig sameAsConfig1;
+ private NeutronConfig config2;
+
+ /**
+ * Tests class immutability.
+ */
+ @Test
+ public void testImmutability() {
+ assertThatClassIsImmutable(DefaultNeutronConfig.class);
+ }
+
+ /**
+ * Initial setup for this unit test.
+ */
+ @Before
+ public void setUp() {
+ config1 = DefaultNeutronConfig.builder()
+ .useMetadataProxy(USE_METADATA_PROXY_1)
+ .metadataProxySecret(METADATA_PROXY_SECRET_1)
+ .build();
+
+ sameAsConfig1 = DefaultNeutronConfig.builder()
+ .useMetadataProxy(USE_METADATA_PROXY_1)
+ .metadataProxySecret(METADATA_PROXY_SECRET_1)
+ .build();
+
+ config2 = DefaultNeutronConfig.builder()
+ .useMetadataProxy(USE_METADATA_PROXY_2)
+ .metadataProxySecret(METADATA_PROXY_SECRET_2)
+ .build();
+ }
+
+ /**
+ * Tests object equality.
+ */
+ @Test
+ public void testEquality() {
+ new EqualsTester().addEqualityGroup(config1, sameAsConfig1)
+ .addEqualityGroup(config2)
+ .testEquals();
+ }
+
+ /**
+ * Test object construction.
+ */
+ @Test
+ public void testConstruction() {
+ NeutronConfig config = config1;
+
+ assertEquals(config.useMetadataProxy(), USE_METADATA_PROXY_1);
+ assertEquals(config.metadataProxySecret(), METADATA_PROXY_SECRET_1);
+ }
+}
diff --git a/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/OpenstackNodeAdapter.java b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/OpenstackNodeAdapter.java
index 68fa85e..d625a05 100644
--- a/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/OpenstackNodeAdapter.java
+++ b/apps/openstacknode/api/src/test/java/org/onosproject/openstacknode/api/OpenstackNodeAdapter.java
@@ -129,16 +129,6 @@
}
@Override
- public OpenstackAuth authentication() {
- return null;
- }
-
- @Override
- public String endpoint() {
- return null;
- }
-
- @Override
public Collection<ControllerInfo> controllers() {
return null;
}
@@ -152,4 +142,14 @@
public DpdkConfig dpdkConfig() {
return null;
}
+
+ @Override
+ public KeystoneConfig keystoneConfig() {
+ return null;
+ }
+
+ @Override
+ public NeutronConfig neutronConfig() {
+ return null;
+ }
}