Merge "user classes of model in onos-nemo"
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/NemoUserData.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/NemoUserData.java
new file mode 100644
index 0000000..e01e9ca
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/NemoUserData.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user;
+
+/**
+ * All Users' information data.
+ */
+public interface NemoUserData {
+ /**
+ * Returns all user roles information.
+ *
+ * @return user roles
+ */
+ UserRoles getUserRoles();
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserInstance.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserInstance.java
new file mode 100644
index 0000000..d9b266b
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserInstance.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user;
+
+import org.onosproject.nemo.model.common.UserId;
+import org.onosproject.nemo.model.common.UserName;
+import org.onosproject.nemo.model.common.UserPassword;
+import org.onosproject.nemo.model.common.UserRoleName;
+
+/**
+ * User instance which contains user information.
+ */
+public interface UserInstance {
+
+ /**
+ * Returns the unique ID for a user.
+ *
+ * @return user id object
+ */
+ UserId getUserId();
+
+ /**
+ * Returns the user-visible and unique name for a user.
+ *
+ * @return user
+ */
+ UserName getUserName();
+
+ /**
+ * Returns the password of a user.
+ *
+ * @return user password
+ */
+ UserPassword getUserPassword();
+
+ /**
+ * Returns the role of a user.
+ *
+ * @return user role name
+ */
+ UserRoleName getUserRole();
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRoles.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRoles.java
new file mode 100644
index 0000000..a600be5
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRoles.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user;
+
+import org.onosproject.nemo.model.user.roles.UserRole;
+
+import java.util.List;
+
+/**
+ * User roles' information.
+ *
+ */
+public interface UserRoles {
+
+ /**
+ * Returns a list of user roles.
+ *
+ * @return user role list
+ */
+ List<UserRole> getUserRoles();
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRolesBuilder.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRolesBuilder.java
new file mode 100644
index 0000000..d49b406
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/UserRolesBuilder.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import org.onosproject.nemo.model.user.roles.UserRole;
+
+/**
+ * The builder of user roles.
+ */
+public class UserRolesBuilder {
+
+ private Map<UserRoles, UserRoles> augmentation = new HashMap<>();
+ private List<UserRole> userRoles;
+
+ /**
+ * Creates a default user roles builder.
+ */
+ public UserRolesBuilder() {
+ }
+
+ /**
+ * Creates a user roles builder from a user roles object.
+ *
+ * @param base the user roles object
+ */
+ public UserRolesBuilder(UserRoles base) {
+ userRoles = base.getUserRoles();
+ }
+
+ /**
+ * Sets the user role list to be used by the builder.
+ *
+ * @param value user role list
+ * @return self
+ */
+ public UserRolesBuilder userRoles(List<UserRole> value) {
+ userRoles = value;
+ return this;
+ }
+
+ /**
+ * Builds the user roles from this instance.
+ *
+ * @return user roles
+ */
+ public UserRoles build() {
+ return new UserRolesImpl(this);
+ }
+
+ /**
+ * The implementation of user role interface to create an instance.
+ */
+ private static final class UserRolesImpl implements UserRoles {
+
+ private final List<UserRole> userRoles;
+ private final Map<UserRoles, UserRoles> augmentation;
+
+ private UserRolesImpl(UserRolesBuilder base) {
+ userRoles = base.userRoles;
+ augmentation = new HashMap<>(base.augmentation);
+ }
+
+ @Override
+ public List<UserRole> getUserRoles() {
+ return userRoles;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(userRoles, augmentation);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null){
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UserRoles other = (UserRoles) obj;
+ if (!Objects.equals(userRoles, other.getUserRoles())) {
+ return false;
+ }
+ UserRolesImpl otherImpl = (UserRolesImpl) obj;
+ return Objects.equals(augmentation, otherImpl.augmentation);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("user roles", userRoles)
+ .add("augmentation", augmentation)
+ .toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/package-info.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/package-info.java
new file mode 100644
index 0000000..3095bd9
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * User classes for NEMO model which describe users' information.
+ */
+package org.onosproject.nemo.model.user;
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRole.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRole.java
new file mode 100644
index 0000000..4fc9fe5
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRole.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user.roles;
+
+import org.onosproject.nemo.model.common.UserRoleDescription;
+import org.onosproject.nemo.model.common.UserRoleName;
+
+/**
+ * Single User role's information.
+ */
+public interface UserRole {
+
+ /**
+ * Returns a user-visible and unique name for a kind of role.
+ *
+ * @return a user-visible and unique name
+ */
+ UserRoleName getRoleName();
+
+ /**
+ * Returns a description of the characteristic,
+ * responsibility and purpose for a kind of role.
+ *
+ * @return a description of the role
+ */
+ UserRoleDescription getRoleDescription();
+
+ /**
+ * Returns the primary key of YANG list type.
+ *
+ * @return the key
+ */
+ UserRoleKey getKey();
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleBuilder.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleBuilder.java
new file mode 100644
index 0000000..a0696f6
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleBuilder.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user.roles;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import org.onosproject.nemo.model.common.UserRoleDescription;
+import org.onosproject.nemo.model.common.UserRoleName;
+
+/**
+ * The builder of user role.
+ */
+public class UserRoleBuilder {
+
+ private Map<UserRole, UserRole> augmentation = new HashMap<>();
+ private UserRoleKey key;
+ private UserRoleDescription roleDescription;
+ private UserRoleName roleName;
+
+ /**
+ * Creates a default user role builder.
+ */
+ public UserRoleBuilder() {
+ }
+
+ /**
+ * Creates a user role builder from a user role object.
+ *
+ * @param base the user role object
+ */
+ public UserRoleBuilder(UserRole base) {
+ if (base.getKey() == null) {
+ key = new UserRoleKey(base.getRoleName());
+ roleName = base.getRoleName();
+ } else {
+ key = base.getKey();
+ roleName = key.getRoleName();
+ }
+ roleDescription = base.getRoleDescription();
+ }
+
+ /**
+ * Sets the key to be used by the builder.
+ *
+ * @param key key value
+ * @return self
+ */
+ public UserRoleBuilder key(UserRoleKey key) {
+ this.key = key;
+ return this;
+ }
+
+ /**
+ * Sets the description to be used by the builder.
+ *
+ * @param desc the role description
+ * @return self
+ */
+ public UserRoleBuilder roleDescription(UserRoleDescription desc) {
+ roleDescription = desc;
+ return this;
+ }
+
+ /**
+ * Sets the role name to be used by the builder.
+ *
+ * @param name user role name
+ * @return self
+ */
+ public UserRoleBuilder roleName(UserRoleName name) {
+ roleName = name;
+ return this;
+ }
+
+ /**
+ * Builds a user role from this builder instance.
+ *
+ * @return user role
+ */
+ public UserRole build() {
+ return new UserRoleImpl(this);
+ }
+
+ /**
+ * The implementation of user role interface.
+ */
+ private static final class UserRoleImpl implements UserRole {
+
+ private final UserRoleKey key;
+ private final UserRoleDescription roleDescription;
+ private final UserRoleName roleName;
+ private final Map<UserRole, UserRole> augmentation;
+
+ private UserRoleImpl(UserRoleBuilder base) {
+ if (base.key == null) {
+ key = new UserRoleKey(base.roleName);
+ roleName = base.roleName;
+ } else {
+ key = base.key;
+ roleName = key.getRoleName();
+ }
+ roleDescription = base.roleDescription;
+ augmentation = new HashMap<>(base.augmentation);
+ }
+
+ @Override
+ public UserRoleKey getKey() {
+ return key;
+ }
+
+ @Override
+ public UserRoleDescription getRoleDescription() {
+ return roleDescription;
+ }
+
+ @Override
+ public UserRoleName getRoleName() {
+ return roleName;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(key, roleDescription, roleName, augmentation);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UserRole other = (UserRole) obj;
+ if (!Objects.equals(roleName, other.getRoleName())) {
+ return false;
+ }
+ if (!Objects.equals(roleDescription,
+ other.getRoleDescription())) {
+ return false;
+ }
+ if (!Objects.equals(key, other.getKey())) {
+ return false;
+ }
+ UserRoleImpl otherImpl = (UserRoleImpl) obj;
+ return Objects.equals(augmentation, otherImpl.augmentation);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("key", key)
+ .add("role description", roleDescription)
+ .add("role name", roleName)
+ .add("augmentation", augmentation)
+ .toString();
+ }
+ }
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleKey.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleKey.java
new file mode 100644
index 0000000..cd53377
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/UserRoleKey.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user.roles;
+
+import org.onosproject.nemo.model.common.UserRoleName;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+import java.util.Objects;
+
+/**
+ * The key to differentiate user roles.
+ */
+public class UserRoleKey {
+ private final UserRoleName roleName;
+
+ /**
+ * Creates a user role key from a given role name.
+ *
+ * @param roleName the role name
+ */
+ public UserRoleKey(UserRoleName roleName) {
+ this.roleName = roleName;
+ }
+
+ /**
+ * Creates a copy from a given user role key instance.
+ *
+ * @param source the user role key
+ */
+ public UserRoleKey(UserRoleKey source) {
+ this.roleName = source.roleName;
+ }
+
+ /**
+ * Returns the user role name of this instance.
+ *
+ * @return role name
+ */
+ public UserRoleName getRoleName() {
+ return roleName;
+ }
+
+ @Override
+ public int hashCode() {
+ return roleName.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UserRoleKey other = (UserRoleKey) obj;
+ return Objects.equals(roleName, other.roleName);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this).add("rolename", roleName).toString();
+ }
+}
\ No newline at end of file
diff --git a/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/package-info.java b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/package-info.java
new file mode 100644
index 0000000..ada7ed5
--- /dev/null
+++ b/nemoengine/src/main/java/org/onosproject/nemo/model/user/roles/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/**
+ * User role classes for NEMO model which describe user role information.
+ */
+package org.onosproject.nemo.model.user.roles;
\ No newline at end of file
diff --git a/nemoengine/src/test/java/org/onosproject/nemo/model/user/UserRolesBuilderTest.java b/nemoengine/src/test/java/org/onosproject/nemo/model/user/UserRolesBuilderTest.java
new file mode 100644
index 0000000..e3f01df
--- /dev/null
+++ b/nemoengine/src/test/java/org/onosproject/nemo/model/user/UserRolesBuilderTest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onosproject.nemo.model.common.UserRoleDescription;
+import org.onosproject.nemo.model.common.UserRoleName;
+import org.onosproject.nemo.model.user.roles.UserRole;
+import org.onosproject.nemo.model.user.roles.UserRoleBuilder;
+
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for {@link UserRolesBuilder}.
+ */
+public class UserRolesBuilderTest {
+
+ private static final String ROLES_ERROR_MSG = "user roles not set";
+ private static final String NAME = "SomeName";
+ private static final String OTHER_NAME = "OtherName";
+ private static final String DESC = "SomeDescription";
+
+ private List<UserRole> roleList;
+ private List<UserRole> otherList;
+ private UserRoles roles;
+ private UserRoles copy;
+ private UserRoles diff;
+ private UserRoleDescription desc;
+ private UserRoleName name;
+ private UserRoleName otherName;
+ private UserRole role;
+ private UserRole otherRole;
+
+ @Test
+ public void buildUserRoleWithUserRoles() {
+ roleList = new ArrayList<>();
+ roles = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ assertEquals(ROLES_ERROR_MSG, roleList, roles.getUserRoles());
+ }
+
+ @Test
+ public void fromUserRoleWithUserRoles() {
+ roleList = new ArrayList<>();
+ roles = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ copy = new UserRolesBuilder(roles).build();
+ assertEquals(ROLES_ERROR_MSG, roleList, copy.getUserRoles());
+ }
+
+ @Test
+ public void equality() {
+ roleList = new ArrayList<>();
+ roles = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ otherList = new ArrayList<>();
+ otherList.add(null);
+ copy = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ diff = new UserRolesBuilder()
+ .userRoles(otherList)
+ .build();
+ new EqualsTester()
+ .addEqualityGroup(roles, copy)
+ .addEqualityGroup(diff)
+ .testEquals();
+ }
+
+ @Test
+ public void equalityTwo() {
+ name = new UserRoleName(NAME);
+ otherName = new UserRoleName(OTHER_NAME);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(name)
+ .build();
+ roleList = new ArrayList<>();
+ roleList.add(role);
+ roles = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ otherList = new ArrayList<>();
+ otherRole = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(otherName)
+ .build();
+ otherList.add(otherRole);
+ copy = new UserRolesBuilder()
+ .userRoles(roleList)
+ .build();
+ diff = new UserRolesBuilder()
+ .userRoles(otherList)
+ .build();
+ new EqualsTester()
+ .addEqualityGroup(roles, copy)
+ .addEqualityGroup(diff)
+ .testEquals();
+ }
+}
\ No newline at end of file
diff --git a/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleBuilderTest.java b/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleBuilderTest.java
new file mode 100644
index 0000000..0ed2cd0
--- /dev/null
+++ b/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleBuilderTest.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user.roles;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onosproject.nemo.model.common.UserRoleDescription;
+import org.onosproject.nemo.model.common.UserRoleName;
+
+import com.google.common.testing.EqualsTester;
+/**
+ * Unit tests for {@link UserRoleBuilder}.
+ */
+public class UserRoleBuilderTest {
+
+ private static final String NAME = "SomeName";
+ private static final String OTHER_NAME = "OtherName";
+ private static final String DESC = "SomeDescription";
+ private static final String NAME_ERROR_MSG = "name not set";
+ private static final String DESC_ERROR_MSG = "description not set";
+ private static final String KEY_ERROR_MSG = "key not set";
+
+ private UserRoleKey key;
+ private UserRoleDescription desc;
+ private UserRoleName name;
+ private UserRoleName otherName;
+ private UserRole role;
+ private UserRole copy;
+ private UserRole diff;
+
+ @Test
+ public void buildUserRoleWithUserRoleKey() {
+ name = new UserRoleName(NAME);
+ key = new UserRoleKey(name);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .key(key)
+ .build();
+ assertEquals(NAME_ERROR_MSG, name, role.getRoleName());
+ assertEquals(KEY_ERROR_MSG, key, role.getKey());
+ assertEquals(DESC_ERROR_MSG, desc, role.getRoleDescription());
+ }
+
+ @Test
+ public void buildUserRoleWithRoleName() {
+ name = new UserRoleName(NAME);
+ key = new UserRoleKey(name);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(name)
+ .build();
+ assertEquals(NAME_ERROR_MSG, name, role.getRoleName());
+ assertEquals(KEY_ERROR_MSG, key, role.getKey());
+ assertEquals(DESC_ERROR_MSG, desc, role.getRoleDescription());
+ }
+
+ @Test
+ public void fromUserRoleWithRoleKey() {
+ name = new UserRoleName(NAME);
+ key = new UserRoleKey(name);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .key(key)
+ .build();
+ copy = new UserRoleBuilder(role).build();
+ assertEquals(NAME_ERROR_MSG, name, copy.getRoleName());
+ assertEquals(KEY_ERROR_MSG, key, copy.getKey());
+ assertEquals(DESC_ERROR_MSG, desc, copy.getRoleDescription());
+ }
+
+ @Test
+ public void fromUserRoleWithRoleName() {
+ name = new UserRoleName(NAME);
+ key = new UserRoleKey(name);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(name)
+ .build();
+ copy = new UserRoleBuilder(role).build();
+ assertEquals(NAME_ERROR_MSG, name, copy.getRoleName());
+ assertEquals(KEY_ERROR_MSG, key, copy.getKey());
+ assertEquals(DESC_ERROR_MSG, desc, copy.getRoleDescription());
+ }
+
+ @Test
+ public void equality() {
+ name = new UserRoleName(NAME);
+ desc = new UserRoleDescription(DESC);
+ role = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(name)
+ .build();
+ copy = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(name)
+ .build();
+ otherName = new UserRoleName(OTHER_NAME);
+ diff = new UserRoleBuilder()
+ .roleDescription(desc)
+ .roleName(otherName)
+ .build();
+ new EqualsTester()
+ .addEqualityGroup(role, copy)
+ .addEqualityGroup(diff)
+ .testEquals();
+ }
+}
\ No newline at end of file
diff --git a/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleKeyTest.java b/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleKeyTest.java
new file mode 100644
index 0000000..d5686be
--- /dev/null
+++ b/nemoengine/src/test/java/org/onosproject/nemo/model/user/roles/UserRoleKeyTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * 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.nemo.model.user.roles;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Test;
+import org.onosproject.nemo.model.common.UserRoleName;
+import org.onosproject.nemo.model.user.roles.UserRoleKey;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for {@link UserRoleKey}.
+ */
+public class UserRoleKeyTest {
+
+ private static final String NAME = "SomeName";
+ private static final String OTHER = "OtherName";
+
+ private UserRoleKey key;
+ private UserRoleKey copy;
+ private UserRoleKey diff;
+
+ @Test
+ public void fromUserRoleName() {
+ key = new UserRoleKey(new UserRoleName(NAME));
+ assertEquals("name not set", NAME, key.getRoleName().getValue());
+ }
+
+ @Test
+ public void copyConstructor() {
+ key = new UserRoleKey(new UserRoleName(NAME));
+ copy = new UserRoleKey(key);
+ new EqualsTester()
+ .addEqualityGroup(key, copy)
+ .testEquals();
+ }
+
+ @Test
+ public void equality() {
+ key = new UserRoleKey(new UserRoleName(NAME));
+ copy = new UserRoleKey(new UserRoleName(NAME));
+ diff = new UserRoleKey(new UserRoleName(OTHER));
+ new EqualsTester()
+ .addEqualityGroup(key, copy)
+ .addEqualityGroup(diff)
+ .testEquals();
+ }
+}
\ No newline at end of file