diff options
| author | Jeremie Bresson | 2013-04-10 17:31:49 +0000 |
|---|---|---|
| committer | Jeremie Bresson | 2013-04-10 17:31:49 +0000 |
| commit | a7ebc1084964c2e41fd84100765c26dec7fb0df5 (patch) | |
| tree | 46040990ee134c29a0fa93943446a32fba17864b | |
| parent | b00f8cd7f129d8d8ad536e34d19c9f13049f84fb (diff) | |
| download | org.eclipse.scout.rt-a7ebc1084964c2e41fd84100765c26dec7fb0df5.tar.gz org.eclipse.scout.rt-a7ebc1084964c2e41fd84100765c26dec7fb0df5.tar.xz org.eclipse.scout.rt-a7ebc1084964c2e41fd84100765c26dec7fb0df5.zip | |
Bug 402301: Migration: UI Independent tests
* Add additional tests (server).
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402301
6 files changed, 400 insertions, 0 deletions
diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/CodeServiceTest.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/CodeServiceTest.java new file mode 100644 index 0000000000..c092bfd5a1 --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/CodeServiceTest.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.code; + +import java.util.List; + +import org.eclipse.scout.commons.CompareUtility; +import org.eclipse.scout.commons.exception.ProcessingException; +import org.eclipse.scout.commons.osgi.BundleClassDescriptor; +import org.eclipse.scout.rt.server.internal.Activator; +import org.eclipse.scout.rt.server.services.common.code.fixture.TestCodeType1; +import org.eclipse.scout.rt.server.services.common.code.fixture.TestCodeType2; +import org.eclipse.scout.rt.shared.services.common.code.ICodeService; +import org.eclipse.scout.rt.testing.server.runner.ScoutServerTestRunner; +import org.eclipse.scout.rt.testing.shared.TestingUtility; +import org.eclipse.scout.service.SERVICES; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceRegistration; + +/** + * Test for {@link ICodeService} + */ +@RunWith(ScoutServerTestRunner.class) +public class CodeServiceTest { + + /* ---------------------------------------------------------------------------------------------- */ + /* Tests for Bug 398323 - CodeService / PermissionService: More fine-grained lookup strategies for finding classes */ + /* ---------------------------------------------------------------------------------------------- */ + + private void testImpl(ICodeService testService, boolean testCodeType1Expected, boolean testCodeType2Expected) { + List<ServiceRegistration> reg = TestingUtility.registerServices(Activator.getDefault().getBundle(), 1000, testService); + try { + ICodeService service = SERVICES.getService(ICodeService.class); + Assert.assertSame(testService, service); + // + BundleClassDescriptor[] result = service.getAllCodeTypeClasses(""); + boolean testCodeType1Found = false; + boolean testCodeType2Found = false; + for (BundleClassDescriptor b : result) { + if (CompareUtility.equals(b.getClassName(), TestCodeType1.class.getName())) { + testCodeType1Found = true; + } + if (CompareUtility.equals(b.getClassName(), TestCodeType2.class.getName())) { + testCodeType2Found = true; + } + } + // + if (testCodeType1Expected) { + Assert.assertTrue("TestCodeType1 class not found (expected: found)", testCodeType1Found); + } + else { + Assert.assertFalse("TestCodeType1 class found (expected: not found)", testCodeType1Found); + } + if (testCodeType2Expected) { + Assert.assertTrue("TestCodeType2 class not found (expected: found)", testCodeType2Found); + } + else { + Assert.assertFalse("TestCodeType2 class found (expected: not found)", testCodeType2Found); + } + } + finally { + TestingUtility.unregisterServices(reg); + } + } + + @Test + public void testDefault() throws ProcessingException { + testImpl(new CodeService_Default_Mock(), true, true); + } + + @Test + public void testIgnoreBundle() throws ProcessingException { + testImpl(new CodeService_IgnoreThisBundle_Mock(), false, false); + } + + @Test + public void testIgnoreClassName() throws ProcessingException { + testImpl(new CodeService_IgnoreClassName1_Mock(), false, true); + } + + @Test + public void testIgnoreClass() throws ProcessingException { + testImpl(new CodeService_IgnoreClass2_Mock(), true, false); + } + + abstract static class AbstractCodeServiceMock extends CodeService { + + public AbstractCodeServiceMock() throws ProcessingException { + super(); + } + + @SuppressWarnings("deprecation") + @Override + public void initializeService() { + } + + @Override + public void initializeService(ServiceRegistration registration) { + } + } + + static class CodeService_Default_Mock extends AbstractCodeServiceMock { + + public CodeService_Default_Mock() throws ProcessingException { + super(); + } + } + + static class CodeService_IgnoreThisBundle_Mock extends AbstractCodeServiceMock { + + public CodeService_IgnoreThisBundle_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptBundle(Bundle bundle, String classPrefix) { + return super.acceptBundle(bundle, classPrefix) && (bundle != Activator.getDefault().getBundle()); + } + } + + static class CodeService_IgnoreClassName1_Mock extends AbstractCodeServiceMock { + + public CodeService_IgnoreClassName1_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptClassName(Bundle bundle, String className) { + return super.acceptClassName(bundle, className) && CompareUtility.notEquals(className, TestCodeType1.class.getName()); + } + } + + static class CodeService_IgnoreClass2_Mock extends AbstractCodeServiceMock { + + public CodeService_IgnoreClass2_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptClass(Bundle bundle, Class<?> c) { + return super.acceptClass(bundle, c) && (c != TestCodeType2.class); + } + } +} diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType1.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType1.java new file mode 100644 index 0000000000..82be6df7b6 --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType1.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.code.fixture; + +import org.eclipse.scout.rt.shared.services.common.code.AbstractCodeType; + +public class TestCodeType1 extends AbstractCodeType<String> { + private static final long serialVersionUID = 1L; + + public static final String ID = "TestCodeType1"; + + @Override + public String getId() { + return ID; + } +} diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType2.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType2.java new file mode 100644 index 0000000000..6fcff92b1e --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/code/fixture/TestCodeType2.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.code.fixture; + +import org.eclipse.scout.rt.shared.services.common.code.AbstractCodeType; + +public class TestCodeType2 extends AbstractCodeType<String> { + private static final long serialVersionUID = 1L; + + public static final String ID = "TestCodeType2"; + + @Override + public String getId() { + return ID; + } +} diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/PermissionServiceTest.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/PermissionServiceTest.java new file mode 100644 index 0000000000..ef129f4d72 --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/PermissionServiceTest.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.security; + +import java.util.List; + +import org.eclipse.scout.commons.CompareUtility; +import org.eclipse.scout.commons.exception.ProcessingException; +import org.eclipse.scout.commons.osgi.BundleClassDescriptor; +import org.eclipse.scout.rt.server.internal.Activator; +import org.eclipse.scout.rt.server.services.common.security.fixture.TestPermission1; +import org.eclipse.scout.rt.server.services.common.security.fixture.TestPermission2; +import org.eclipse.scout.rt.shared.services.common.security.IPermissionService; +import org.eclipse.scout.rt.testing.server.runner.ScoutServerTestRunner; +import org.eclipse.scout.rt.testing.shared.TestingUtility; +import org.eclipse.scout.service.SERVICES; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.osgi.framework.Bundle; +import org.osgi.framework.ServiceRegistration; + +/** + * Test for {@link IPermissionService} + */ +@RunWith(ScoutServerTestRunner.class) +public class PermissionServiceTest { + + /* ---------------------------------------------------------------------------------------------- */ + /* Tests for Bug 398323 - CodeService / PermissionService: More fine-grained lookup strategies for finding classes */ + /* ---------------------------------------------------------------------------------------------- */ + + private void testImpl(IPermissionService testService, boolean testPermission1Expected, boolean testPermission2Expected) { + List<ServiceRegistration> reg = TestingUtility.registerServices(Activator.getDefault().getBundle(), 1000, testService); + try { + IPermissionService service = SERVICES.getService(IPermissionService.class); + Assert.assertSame(testService, service); + // + BundleClassDescriptor[] result = service.getAllPermissionClasses(); + boolean testPermission1Found = false; + boolean testPermission2Found = false; + for (BundleClassDescriptor b : result) { + if (CompareUtility.equals(b.getClassName(), TestPermission1.class.getName())) { + testPermission1Found = true; + } + if (CompareUtility.equals(b.getClassName(), TestPermission2.class.getName())) { + testPermission2Found = true; + } + } + // + if (testPermission1Expected) { + Assert.assertTrue("TestPermission1 class not found (expected: found)", testPermission1Found); + } + else { + Assert.assertFalse("TestPermission1 class found (expected: not found)", testPermission1Found); + } + if (testPermission2Expected) { + Assert.assertTrue("TestPermission2 class not found (expected: found)", testPermission2Found); + } + else { + Assert.assertFalse("TestPermission2 class found (expected: not found)", testPermission2Found); + } + } + finally { + TestingUtility.unregisterServices(reg); + } + } + + @Test + public void testDefault() throws ProcessingException { + testImpl(new PermissionService_Default_Mock(), true, true); + } + + @Test + public void testIgnoreBundle() throws ProcessingException { + testImpl(new PermissionService_IgnoreThisBundle_Mock(), false, false); + } + + @Test + public void testIgnoreClassName() throws ProcessingException { + testImpl(new PermissionService_IgnoreClassName1_Mock(), false, true); + } + + @Test + public void testIgnoreClass() throws ProcessingException { + testImpl(new PermissionService_IgnoreClass2_Mock(), true, false); + } + + abstract static class AbstractPermissionServiceMock extends PermissionService { + + public AbstractPermissionServiceMock() throws ProcessingException { + super(); + } + + @SuppressWarnings("deprecation") + @Override + public void initializeService() { + } + + @Override + public void initializeService(ServiceRegistration registration) { + } + } + + static class PermissionService_Default_Mock extends AbstractPermissionServiceMock { + + public PermissionService_Default_Mock() throws ProcessingException { + super(); + } + } + + static class PermissionService_IgnoreThisBundle_Mock extends AbstractPermissionServiceMock { + + public PermissionService_IgnoreThisBundle_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptBundle(Bundle bundle) { + return super.acceptBundle(bundle) && (bundle != Activator.getDefault().getBundle()); + } + } + + static class PermissionService_IgnoreClassName1_Mock extends AbstractPermissionServiceMock { + + public PermissionService_IgnoreClassName1_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptClassName(Bundle bundle, String className) { + return super.acceptClassName(bundle, className) && CompareUtility.notEquals(className, TestPermission1.class.getName()); + } + } + + static class PermissionService_IgnoreClass2_Mock extends AbstractPermissionServiceMock { + + public PermissionService_IgnoreClass2_Mock() throws ProcessingException { + super(); + } + + @Override + protected boolean acceptClass(Bundle bundle, Class<?> c) { + return super.acceptClass(bundle, c) && (c != TestPermission2.class); + } + } +} diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission1.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission1.java new file mode 100644 index 0000000000..3ab7552d9c --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission1.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.security.fixture; + +import java.security.BasicPermission; + +public class TestPermission1 extends BasicPermission { + private static final long serialVersionUID = 1L; + + public TestPermission1() { + super("test.permission.1"); + } +} diff --git a/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission2.java b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission2.java new file mode 100644 index 0000000000..ef0d861617 --- /dev/null +++ b/org.eclipse.scout.rt.server.test/src/org/eclipse/scout/rt/server/services/common/security/fixture/TestPermission2.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2013 BSI Business Systems Integration AG. + * 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: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.server.services.common.security.fixture; + +import java.security.BasicPermission; + +public class TestPermission2 extends BasicPermission { + private static final long serialVersionUID = 1L; + + public TestPermission2() { + super("test.permission.2"); + } +} |
