You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by aw...@apache.org on 2009/11/30 00:28:31 UTC
svn commit: r885295 - in
/incubator/aries/trunk/jmx/jmx-core/src/test/java/org: ./ apache/
apache/aries/ apache/aries/jmx/ apache/aries/jmx/framework/
apache/aries/jmx/permissionadmin/
Author: awojtuniak
Date: Sun Nov 29 23:28:30 2009
New Revision: 885295
URL: http://svn.apache.org/viewvc?rev=885295&view=rev
Log:
ARIES-32 ARIES-50 Added 2 test cases for PackageState and PermissionAdmin
Added:
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java (with props)
Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java?rev=885295&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java Sun Nov 29 23:28:30 2009
@@ -0,0 +1,113 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.aries.jmx.framework;
+
+import java.io.IOException;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.osgi.jmx.framework.PackageStateMBean;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * {@link PackageStateMBean} test case.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class PackageStateTest {
+
+ @Mock
+ private BundleContext context;
+ @Mock
+ private PackageAdmin admin;
+ private PackageState mbean;
+
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mbean = new PackageState(context, admin);
+ }
+
+ @Test
+ public void testGetExportingBundle() throws IOException {
+ ExportedPackage exported = Mockito.mock(ExportedPackage.class);
+ Bundle bundle = Mockito.mock(Bundle.class);
+ Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
+ Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
+ Mockito.when(bundle.getBundleId()).thenReturn(new Long(5));
+ Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported});
+ long id = mbean.getExportingBundle("test", "1.0.0");
+ Assert.assertEquals(5, id);
+
+ }
+
+ @Test
+ public void testGetImportingBundles() throws IOException {
+ ExportedPackage exported = Mockito.mock(ExportedPackage.class);
+ Bundle bundle = Mockito.mock(Bundle.class);
+ Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
+ Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[]{bundle});
+ Mockito.when(bundle.getBundleId()).thenReturn(new Long(4));
+ Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported});
+ long[] ids = mbean.getImportingBundles("test", "1.0.0");
+ Assert.assertArrayEquals(new long[]{4}, ids);
+ }
+
+ @Test
+ public void testIsRemovalPending() throws IOException {
+ ExportedPackage exported = Mockito.mock(ExportedPackage.class);
+ Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
+ Mockito.when(exported.isRemovalPending()).thenReturn(true);
+ Mockito.when(admin.getExportedPackages(Mockito.anyString())).thenReturn(new ExportedPackage[]{exported});
+ boolean isRemoval = mbean.isRemovalPending("test", "1.0.0");
+ Assert.assertTrue(isRemoval);
+ }
+
+ @Test
+ public void testListPackages() throws IOException {
+ Bundle bundle = Mockito.mock(Bundle.class);
+ Bundle impBundle = Mockito.mock(Bundle.class);
+ Mockito.when(context.getBundles()).thenReturn(new Bundle[]{bundle});
+ ExportedPackage exported = Mockito.mock(ExportedPackage.class);
+ Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
+ Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[]{impBundle});
+ Mockito.when(exported.getName()).thenReturn("test");
+ Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
+ Mockito.when(bundle.getBundleId()).thenReturn(new Long(4));
+ Mockito.when(impBundle.getBundleId()).thenReturn(new Long(5));
+ Mockito.when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[]{exported});
+ TabularData table = mbean.listPackages();
+ Assert.assertEquals(PackageStateMBean.PACKAGES_TYPE,table.getTabularType());
+ CompositeData data = table.get(new Object[]{"test", "1.0.0", new Long(4)});
+ Assert.assertNotNull(data);
+
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/PackageStateTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java?rev=885295&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java Sun Nov 29 23:28:30 2009
@@ -0,0 +1,124 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.aries.jmx.permissionadmin;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.osgi.jmx.service.permissionadmin.PermissionAdminMBean;
+import org.osgi.service.permissionadmin.PermissionInfo;
+
+/**
+ * {@link PermissionAdminMBean} test case.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class PermissionAdminTest {
+
+ @Mock
+ private org.osgi.service.permissionadmin.PermissionAdmin permAdmin;
+ private PermissionAdminMBean mbean;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mbean = new PermissionAdmin(permAdmin);
+ }
+
+ @Test
+ public void testGetPermissions() throws IOException {
+ PermissionInfo info = new PermissionInfo("Admin", "test", "get");
+ PermissionInfo[] permInfos = new PermissionInfo[] { info, info };
+
+ Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(permInfos);
+ String[] permissions = mbean.getPermissions("test");
+
+ Assert.assertNotNull(permissions);
+ Assert.assertEquals(2, permissions.length);
+ Assert.assertArrayEquals("Checks encoded permissions", new String[] { info.getEncoded(), info.getEncoded() },
+ permissions);
+
+ Mockito.reset(permAdmin);
+ Mockito.when(permAdmin.getPermissions(Mockito.anyString())).thenReturn(null);
+ String[] permissions2 = mbean.getPermissions("test");
+
+ Assert.assertNull(permissions2);
+ }
+
+ @Test
+ public void testListDefaultPermissions() throws IOException {
+ PermissionInfo info = new PermissionInfo("Admin", "test", "get");
+ PermissionInfo[] permInfos = new PermissionInfo[] { info, info };
+
+ Mockito.when(permAdmin.getDefaultPermissions()).thenReturn(permInfos);
+ String[] permissions = mbean.listDefaultPermissions();
+
+ Assert.assertNotNull(permissions);
+ Assert.assertEquals(2, permissions.length);
+ Assert.assertArrayEquals("Checks encoded default permissions", new String[] { info.getEncoded(), info.getEncoded() },
+ permissions);
+
+ Mockito.reset(permAdmin);
+ Mockito.when(permAdmin.getDefaultPermissions()).thenReturn(null);
+ String[] permissions2 = mbean.listDefaultPermissions();
+
+ Assert.assertNull(permissions2);
+ }
+
+ @Test
+ public void testListLocations() throws IOException {
+ String[] locations1 = new String[] { "test1", "test2" };
+ Mockito.when(permAdmin.getLocations()).thenReturn(locations1);
+ String[] locations2 = mbean.listLocations();
+ Assert.assertNotNull(locations2);
+ Assert.assertEquals(2, locations2.length);
+ Assert.assertSame(locations1, locations2);
+ }
+
+ @Test
+ public void testSetDefaultPermissions() throws IOException {
+ PermissionInfo info1 = new PermissionInfo("Admin", "test", "get");
+ PermissionInfo info2 = new PermissionInfo("Admin", "test2", "get");
+ PermissionInfo[] permInfos = new PermissionInfo[] { info1, info2 };
+ String[] encodedPermissions = new String[2];
+ int i = 0;
+ for (PermissionInfo info : permInfos) {
+ encodedPermissions[i++] = info.getEncoded();
+ }
+ mbean.setDefaultPermissions(encodedPermissions);
+ }
+
+ @Test
+ public void testSetPermissions() throws IOException {
+ PermissionInfo info1 = new PermissionInfo("Admin", "test", "set");
+ PermissionInfo info2 = new PermissionInfo("Admin", "test2", "set");
+ PermissionInfo[] permInfos = new PermissionInfo[] { info1, info2 };
+ String[] encodedPermissions = new String[2];
+ int i = 0;
+ for (PermissionInfo info : permInfos) {
+ encodedPermissions[i++] = info.getEncoded();
+ }
+ mbean.setPermissions("test", encodedPermissions);
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Date