Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-06-07 00:17:58 -0400
committerRoberto E. Escobar2014-06-18 13:21:20 -0400
commit3f0b3f1feb61e00cf2100396b233f6b819d883ee (patch)
tree1aedc35698c792f77ac12d83cf22e281dedecaf2 /plugins/org.eclipse.osee.orcs.account.admin.test
parent72650555ae15a8b604d5f0e92019d4d4deadea76 (diff)
downloadorg.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.tar.gz
org.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.tar.xz
org.eclipse.osee-3f0b3f1feb61e00cf2100396b233f6b819d883ee.zip
feature[ats_ATS64153]: Create ORCS Account Subscriptions storage
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.account.admin.test')
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/OrcsAccountTestSuite.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OrcsSubscriptionStorageTest.java154
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OsgiIntegrationTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/OrcsAccountInternalTestSuite.java23
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtilTest.java108
5 files changed, 288 insertions, 2 deletions
diff --git a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/OrcsAccountTestSuite.java b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/OrcsAccountTestSuite.java
index 3e0c0eac99..7ccb349e6f 100644
--- a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/OrcsAccountTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/OrcsAccountTestSuite.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.orcs.account.admin;
import org.eclipse.osee.orcs.account.admin.integration.OsgiIntegrationTestSuite;
+import org.eclipse.osee.orcs.account.admin.internal.OrcsAccountInternalTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -18,7 +19,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({OsgiIntegrationTestSuite.class})
+@Suite.SuiteClasses({OsgiIntegrationTestSuite.class, OrcsAccountInternalTestSuite.class})
public class OrcsAccountTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OrcsSubscriptionStorageTest.java b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OrcsSubscriptionStorageTest.java
new file mode 100644
index 0000000000..3b3306aff0
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OrcsSubscriptionStorageTest.java
@@ -0,0 +1,154 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.account.admin.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.AccountPreferences;
+import org.eclipse.osee.account.admin.CreateAccountRequest;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.account.admin.SubscriptionGroup;
+import org.eclipse.osee.account.admin.ds.AccountStorage;
+import org.eclipse.osee.account.admin.ds.SubscriptionStorage;
+import org.eclipse.osee.framework.jdk.core.type.Identifiable;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.orcs.account.admin.internal.OrcsSubscriptionStorage;
+import org.eclipse.osee.orcs.db.mock.OsgiService;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TestName;
+import org.junit.rules.TestRule;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link OrcsSubscriptionStorage}
+ *
+ * @author Roberto E. Escobar
+ */
+public class OrcsSubscriptionStorageTest {
+
+ private static final String SUBSCRIPTION_GROUP = "Subscription-Group1";
+
+ @Rule
+ public TestRule osgi = OrcsIntegrationRule.integrationRule(this, "osee.demo.hsql");
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @OsgiService
+ private SubscriptionStorage storage;
+
+ @OsgiService
+ private AccountStorage accountStorage;
+
+ // @formatter:off
+ @Mock private CreateAccountRequest request;
+ @Mock private AccountPreferences preferences;
+ // @formatter:on
+
+ private String name;
+ private String email;
+ private String username;
+ private boolean active;
+ private Map<String, String> prefs;
+
+ private Identifiable<String> newAccount;
+
+ @Before
+ public void testSetup() {
+ initMocks(this);
+
+ String methodName = testName.getMethodName();
+
+ name = String.format("displayName-%s", methodName);
+ email = String.format("%s@email.com", methodName);
+ username = String.format("userName-%s", methodName);
+ active = true;
+
+ prefs = new HashMap<String, String>();
+ prefs.put("a", "1");
+ prefs.put("b", "2");
+ prefs.put("c", "true");
+
+ when(request.getDisplayName()).thenReturn(name);
+ when(request.getEmail()).thenReturn(email);
+ when(request.getUserName()).thenReturn(username);
+ when(request.getPreferences()).thenReturn(prefs);
+ when(request.isActive()).thenReturn(active);
+
+ newAccount = accountStorage.createAccount(request);
+ }
+
+ @Test
+ public void testSubscriptionAPI() {
+ Account account = accountStorage.getAccountByUuid(newAccount.getGuid()).getExactlyOne();
+
+ long accountId = account.getId();
+ ResultSet<Subscription> results = storage.getSubscriptionsByAccountLocalId(accountId);
+ assertEquals(true, results.isEmpty());
+
+ assertEquals(false, storage.subscriptionGroupNameExists(SUBSCRIPTION_GROUP));
+
+ SubscriptionGroup group = storage.createSubscriptionGroup(SUBSCRIPTION_GROUP);
+ assertNotNull(group);
+
+ assertEquals(true, storage.subscriptionGroupNameExists(SUBSCRIPTION_GROUP));
+
+ SubscriptionGroup group1 = storage.getSubscriptionGroups().getExactlyOne();
+ assertEquals(group, group1);
+
+ ResultSet<Account> members = storage.getSubscriptionGroupMembersByLocalId(group.getId());
+ assertEquals(true, members.isEmpty());
+
+ Subscription subscription = storage.getSubscriptionsByAccountLocalId(account.getId()).getExactlyOne();
+ assertEquals(group.getId(), subscription.getGroupId());
+ assertEquals(group.getName(), subscription.getName());
+ assertEquals(account.getId(), subscription.getAccountId());
+ assertEquals(account.getName(), subscription.getAccountName());
+
+ assertEquals(false, subscription.isActive());
+
+ // Activate Subscription
+ storage.updateSubscription(subscription.getAccountId(), subscription.getGroupId(), true);
+
+ String subscriptionUuid = subscription.getGuid();
+ subscription = storage.getSubscription(subscriptionUuid);
+ assertEquals(true, subscription.isActive());
+
+ members = storage.getSubscriptionGroupMembersByLocalId(group.getId());
+ assertEquals(1, members.size());
+ Account member = members.getExactlyOne();
+ assertEquals(account, member);
+
+ // De-Activate Subscription
+ storage.updateSubscription(subscription.getAccountId(), subscription.getGroupId(), false);
+
+ subscription = storage.getSubscription(subscriptionUuid);
+ assertEquals(false, subscription.isActive());
+
+ members = storage.getSubscriptionGroupMembersByLocalId(group.getId());
+ assertEquals(true, members.isEmpty());
+
+ storage.deleteSubscriptionGroup(group);
+ assertEquals(false, storage.subscriptionGroupNameExists(SUBSCRIPTION_GROUP));
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OsgiIntegrationTestSuite.java b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OsgiIntegrationTestSuite.java
index b0cc10a2bd..2641093105 100644
--- a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OsgiIntegrationTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/integration/OsgiIntegrationTestSuite.java
@@ -17,7 +17,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({OrcsAccountStorageTest.class})
+@Suite.SuiteClasses({OrcsAccountStorageTest.class, OrcsSubscriptionStorageTest.class})
public class OsgiIntegrationTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/OrcsAccountInternalTestSuite.java b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/OrcsAccountInternalTestSuite.java
new file mode 100644
index 0000000000..5275be3191
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/OrcsAccountInternalTestSuite.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.account.admin.internal;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({SubscriptionUtilTest.class})
+public class OrcsAccountInternalTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtilTest.java b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtilTest.java
new file mode 100644
index 0000000000..cd2cb76185
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.account.admin.test/src/org/eclipse/osee/orcs/account/admin/internal/SubscriptionUtilTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.account.admin.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import org.eclipse.osee.account.admin.Subscription;
+import org.eclipse.osee.orcs.account.admin.internal.SubscriptionUtil.ActiveDelegate;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Test Case for {@link SubscriptionUtil}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SubscriptionUtilTest {
+
+ private static final int ACCOUNT_ID = 3242;
+ private static final String ACCOUNT_NAME = "account-name";
+
+ private static final int GROUP_ID = 97012;
+ private static final String SUBSCRIPTION_NAME = "subscription-name";
+
+ @Test
+ public void testEncodeDecodeSubscription() {
+ String encodedUuid = SubscriptionUtil.toEncodedUuid(ACCOUNT_ID, ACCOUNT_NAME, GROUP_ID, SUBSCRIPTION_NAME);
+
+ ActiveDelegate delegate = Mockito.mock(ActiveDelegate.class);
+
+ Subscription actual = SubscriptionUtil.fromEncodedUuid(encodedUuid, delegate);
+ assertEquals(encodedUuid, actual.getGuid());
+ assertEquals(SUBSCRIPTION_NAME, actual.getName());
+ assertEquals(ACCOUNT_ID, actual.getAccountId());
+ assertEquals(ACCOUNT_NAME, actual.getAccountName());
+ assertEquals(GROUP_ID, actual.getGroupId());
+
+ when(delegate.isActive(ACCOUNT_ID, GROUP_ID)).thenReturn(true);
+ boolean isActive = actual.isActive();
+
+ assertEquals(true, isActive);
+ verify(delegate).isActive(ACCOUNT_ID, GROUP_ID);
+ }
+
+ @Test
+ public void testFromData() {
+ String encodedUuid = SubscriptionUtil.toEncodedUuid(ACCOUNT_ID, ACCOUNT_NAME, GROUP_ID, SUBSCRIPTION_NAME);
+
+ Subscription actual =
+ SubscriptionUtil.fromData(ACCOUNT_ID, ACCOUNT_NAME, GROUP_ID, SUBSCRIPTION_NAME, true);
+
+ assertEquals(encodedUuid, actual.getGuid());
+ assertEquals(SUBSCRIPTION_NAME, actual.getName());
+ assertEquals(ACCOUNT_ID, actual.getAccountId());
+ assertEquals(ACCOUNT_NAME, actual.getAccountName());
+ assertEquals(GROUP_ID, actual.getGroupId());
+ assertEquals(true, actual.isActive());
+
+ actual = SubscriptionUtil.fromData(ACCOUNT_ID, ACCOUNT_NAME, GROUP_ID, SUBSCRIPTION_NAME, false);
+
+ assertEquals(encodedUuid, actual.getGuid());
+ assertEquals(SUBSCRIPTION_NAME, actual.getName());
+ assertEquals(ACCOUNT_ID, actual.getAccountId());
+ assertEquals(ACCOUNT_NAME, actual.getAccountName());
+ assertEquals(GROUP_ID, actual.getGroupId());
+ assertEquals(false, actual.isActive());
+ }
+
+ public void testFromArtifactData() {
+ String encodedUuid = SubscriptionUtil.toEncodedUuid(ACCOUNT_ID, ACCOUNT_NAME, GROUP_ID, SUBSCRIPTION_NAME);
+
+ ArtifactReadable accountArt = Mockito.mock(ArtifactReadable.class);
+ when(accountArt.getLocalId()).thenReturn(ACCOUNT_ID);
+ when(accountArt.getName()).thenReturn(ACCOUNT_NAME);
+
+ ArtifactReadable subscriptionArt = Mockito.mock(ArtifactReadable.class);
+ when(subscriptionArt.getLocalId()).thenReturn(GROUP_ID);
+ when(subscriptionArt.getName()).thenReturn(SUBSCRIPTION_NAME);
+
+ Subscription actual = SubscriptionUtil.fromArtifactData(accountArt, subscriptionArt, true);
+
+ assertEquals(encodedUuid, actual.getGuid());
+ assertEquals(SUBSCRIPTION_NAME, actual.getName());
+ assertEquals(ACCOUNT_ID, actual.getAccountId());
+ assertEquals(ACCOUNT_NAME, actual.getAccountName());
+ assertEquals(GROUP_ID, actual.getGroupId());
+ assertEquals(true, actual.isActive());
+
+ actual = SubscriptionUtil.fromArtifactData(accountArt, subscriptionArt, false);
+
+ assertEquals(encodedUuid, actual.getGuid());
+ assertEquals(SUBSCRIPTION_NAME, actual.getName());
+ assertEquals(ACCOUNT_ID, actual.getAccountId());
+ assertEquals(ACCOUNT_NAME, actual.getAccountName());
+ assertEquals(GROUP_ID, actual.getGroupId());
+ assertEquals(false, actual.isActive());
+ }
+}

Back to the top