diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-03-10 22:40:51 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-03-14 07:59:12 +0200 |
commit | a6653d3fe49e6a97468ac09f7f2f4d621bea1078 (patch) | |
tree | 96c82e20ca6551ee4c14c8877f0258b25c63cddf /server/tests/src/com/vaadin/util | |
parent | f7e57d77ce621ee39167369c31d989edc5633266 (diff) | |
download | vaadin-framework-a6653d3fe49e6a97468ac09f7f2f4d621bea1078.tar.gz vaadin-framework-a6653d3fe49e6a97468ac09f7f2f4d621bea1078.zip |
Migrate vaadin-server build to maven
Change-Id: I5c740f4e9cb28103bab199f9a552153d82277e7e
Diffstat (limited to 'server/tests/src/com/vaadin/util')
3 files changed, 0 insertions, 337 deletions
diff --git a/server/tests/src/com/vaadin/util/CurrentInstanceTest.java b/server/tests/src/com/vaadin/util/CurrentInstanceTest.java deleted file mode 100644 index 458e8a2f6c..0000000000 --- a/server/tests/src/com/vaadin/util/CurrentInstanceTest.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * 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 com.vaadin.util; - -import static org.junit.Assert.assertNull; - -import java.lang.ref.WeakReference; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinService; -import com.vaadin.server.VaadinSession; -import com.vaadin.ui.UI; - -public class CurrentInstanceTest { - - @Before - public void clearExistingThreadLocals() { - // Ensure no previous test left some thread locals hanging - CurrentInstance.clearAll(); - } - - @Test - public void testInitiallyCleared() throws Exception { - assertCleared(); - } - - @Test - public void testClearedAfterRemove() throws Exception { - CurrentInstance.set(CurrentInstanceTest.class, this); - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - CurrentInstance.set(CurrentInstanceTest.class, null); - - assertCleared(); - } - - @Test - public void testClearedAfterRemoveInheritable() throws Exception { - CurrentInstance.clearAll(); - - CurrentInstance.setInheritable(CurrentInstanceTest.class, this); - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - CurrentInstance.setInheritable(CurrentInstanceTest.class, null); - - assertCleared(); - } - - @Test - public void testInheritableThreadLocal() throws Exception { - final AtomicBoolean threadFailed = new AtomicBoolean(true); - - CurrentInstance.setInheritable(CurrentInstanceTest.class, this); - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - Thread t = new Thread() { - @Override - public void run() { - Assert.assertEquals(CurrentInstanceTest.this, - CurrentInstance.get(CurrentInstanceTest.class)); - threadFailed.set(false); - } - }; - t.start(); - CurrentInstance.set(CurrentInstanceTest.class, null); - - assertCleared(); - while (t.isAlive()) { - Thread.sleep(1000); - } - Assert.assertFalse("Thread failed", threadFailed.get()); - - } - - @Test - public void testClearedAfterRemoveInSeparateThread() throws Exception { - final AtomicBoolean threadFailed = new AtomicBoolean(true); - - CurrentInstance.setInheritable(CurrentInstanceTest.class, this); - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - Thread t = new Thread() { - @Override - public void run() { - try { - Assert.assertEquals(CurrentInstanceTest.this, - CurrentInstance.get(CurrentInstanceTest.class)); - CurrentInstance.set(CurrentInstanceTest.class, null); - assertCleared(); - - threadFailed.set(false); - } catch (Exception e) { - e.printStackTrace(); - } - } - }; - t.start(); - - while (t.isAlive()) { - Thread.sleep(1000); - } - Assert.assertFalse("Thread failed", threadFailed.get()); - - // Clearing the threadlocal in the thread should not have cleared it - // here - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - - // Clearing the only remaining threadlocal should free all memory - CurrentInstance.set(CurrentInstanceTest.class, null); - assertCleared(); - } - - @Test - public void testClearedWithClearAll() throws Exception { - CurrentInstance.set(CurrentInstanceTest.class, this); - Assert.assertEquals(this, - CurrentInstance.get(CurrentInstanceTest.class)); - CurrentInstance.clearAll(); - - assertCleared(); - } - - private void assertCleared() throws SecurityException, - NoSuchFieldException, IllegalAccessException { - Assert.assertNull(getInternalCurrentInstanceVariable().get()); - } - - private InheritableThreadLocal<Map<Class<?>, CurrentInstance>> getInternalCurrentInstanceVariable() - throws SecurityException, NoSuchFieldException, - IllegalAccessException { - Field f = CurrentInstance.class.getDeclaredField("instances"); - f.setAccessible(true); - return (InheritableThreadLocal<Map<Class<?>, CurrentInstance>>) f - .get(null); - } - - public void testInheritedClearedAfterRemove() { - - } - - private static class UIStoredInCurrentInstance extends UI { - @Override - protected void init(VaadinRequest request) { - } - } - - private static class SessionStoredInCurrentInstance extends VaadinSession { - public SessionStoredInCurrentInstance(VaadinService service) { - super(service); - } - } - - @Test - public void testRestoringNullUIWorks() throws Exception { - // First make sure current instance is empty - CurrentInstance.clearAll(); - - // Then store a new UI in there - Map<Class<?>, CurrentInstance> old = CurrentInstance - .setCurrent(new UIStoredInCurrentInstance()); - - // Restore the old values and assert that the UI is null again - CurrentInstance.restoreInstances(old); - assertNull(CurrentInstance.get(UI.class)); - } - - @Test - public void testRestoringNullSessionWorks() throws Exception { - // First make sure current instance is empty - CurrentInstance.clearAll(); - - // Then store a new session in there - Map<Class<?>, CurrentInstance> old = CurrentInstance - .setCurrent(new SessionStoredInCurrentInstance(EasyMock - .createNiceMock(VaadinService.class))); - - // Restore the old values and assert that the session is null again - CurrentInstance.restoreInstances(old); - assertNull(CurrentInstance.get(VaadinSession.class)); - assertNull(CurrentInstance.get(VaadinService.class)); - } - - @Test - public void testRestoreWithGarbageCollectedValue() - throws InterruptedException { - VaadinSession session1 = new VaadinSession(null) { - @Override - public String toString() { - return "First session"; - } - }; - VaadinSession session2 = new VaadinSession(null) { - @Override - public String toString() { - return "Second session"; - } - }; - - VaadinSession.setCurrent(session1); - Map<Class<?>, CurrentInstance> previous = CurrentInstance - .setCurrent(session2); - - // Use weak ref to verify object is collected - WeakReference<VaadinSession> ref = new WeakReference<VaadinSession>( - session1); - - session1 = null; - waitUntilGarbageCollected(ref); - - CurrentInstance.restoreInstances(previous); - - Assert.assertNull(VaadinSession.getCurrent()); - } - - private static void waitUntilGarbageCollected(WeakReference<?> ref) - throws InterruptedException { - for (int i = 0; i < 50; i++) { - System.gc(); - if (ref.get() == null) { - return; - } - Thread.sleep(100); - } - Assert.fail("Value was not garbage collected."); - } -} diff --git a/server/tests/src/com/vaadin/util/ReflectToolsGetFieldValueByTypeTest.java b/server/tests/src/com/vaadin/util/ReflectToolsGetFieldValueByTypeTest.java deleted file mode 100644 index 67796314c0..0000000000 --- a/server/tests/src/com/vaadin/util/ReflectToolsGetFieldValueByTypeTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.vaadin.util; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Test; - -public class ReflectToolsGetFieldValueByTypeTest { - @Test - public void getFieldValue() { - class MyClass { - public Integer getField() { - return 1; - } - - public void setField(Integer i) { - } - - } - class MySubClass extends MyClass { - public String field = "Hello"; - } - - MySubClass myInstance = new MySubClass(); - - java.lang.reflect.Field memberField; - Object fieldValue = new Boolean(false); - try { - memberField = myInstance.getClass().getField("field"); - // Should get a String value. Without the third parameter (calling - // ReflectTools.getJavaFieldValue(Object object, Field field)) would - // get an Integer value - fieldValue = ReflectTools.getJavaFieldValue(myInstance, - memberField, String.class); - } catch (Exception e) { - } - assertTrue(fieldValue instanceof String); - - } - - @Test - public void getFieldValueViaGetter() { - class MyClass { - public Integer field = 1; - } - class MySubClass extends MyClass { - public String field = "Hello"; - } - - MySubClass myInstance = new MySubClass(); - - java.lang.reflect.Field memberField; - try { - memberField = myInstance.getClass().getField("field"); - // Should throw an IllegalArgument exception as the mySubClass class - // doesn't have an Integer field. - ReflectTools.getJavaFieldValue(myInstance, memberField, - Integer.class); - fail("Previous method call should have thrown an exception"); - } catch (Exception e) { - } - } -} diff --git a/server/tests/src/com/vaadin/util/ReflectToolsGetPrimitiveFieldValueTest.java b/server/tests/src/com/vaadin/util/ReflectToolsGetPrimitiveFieldValueTest.java deleted file mode 100644 index 40e8f05e1e..0000000000 --- a/server/tests/src/com/vaadin/util/ReflectToolsGetPrimitiveFieldValueTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.vaadin.util; - -import static org.junit.Assert.assertFalse; - -import org.junit.Test; - -public class ReflectToolsGetPrimitiveFieldValueTest { - @Test - public void getFieldValueViaGetter() { - class MyClass { - public int field = 1; - } - - MyClass myInstance = new MyClass(); - - java.lang.reflect.Field memberField; - Object fieldValue = new Boolean(false); - try { - memberField = myInstance.getClass().getField("field"); - fieldValue = ReflectTools - .getJavaFieldValue(myInstance, memberField); - } catch (Exception e) { - } - assertFalse(fieldValue instanceof Boolean); - } -} |