diff --git a/src/main/java/org/intellimate/izou/security/ReflectionPermissionModule.java b/src/main/java/org/intellimate/izou/security/ReflectionPermissionModule.java index 7a60238d..30c0f9db 100644 --- a/src/main/java/org/intellimate/izou/security/ReflectionPermissionModule.java +++ b/src/main/java/org/intellimate/izou/security/ReflectionPermissionModule.java @@ -18,6 +18,7 @@ public class ReflectionPermissionModule extends PermissionModule { public ReflectionPermissionModule(Main main, SecurityManager securityManager) { super(main, securityManager); // Security package + //Leander: I don't think this is a good idea forbiddenReflections = new ArrayList<>(); forbiddenReflections.add(AudioPermissionModule.class); forbiddenReflections.add(FilePermissionModule.class); diff --git a/src/test/java/classLoaderUtil/DifferentClassLoaderUtils.java b/src/test/java/classLoaderUtil/DifferentClassLoaderUtils.java new file mode 100644 index 00000000..ab63ff69 --- /dev/null +++ b/src/test/java/classLoaderUtil/DifferentClassLoaderUtils.java @@ -0,0 +1,98 @@ +package classLoaderUtil; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.function.Supplier; + +/** + * @author LeanderK + * @version 1.0 + */ +public class DifferentClassLoaderUtils { + /** + * do not use this method! It does nothing....but i don't want to mess with access checks since this class + * can be used for testing reflection. + * @param supplier the supplier + * @param the return type + * @return returns the result from the supplier + */ + public A doMethod(Supplier supplier) { + return supplier.get(); + } + + public SupplierExcpts doMethodWithDiffClassloader(Supplier supplier) throws Exception{ + URL url = this.getClass().getClassLoader().getResource(this.getClass().getName()); + URL[] urls = {url}; + URLClassLoader classLoader = new URLClassLoader(urls, this.getClass().getClassLoader()) { + @Override + public Class loadClass(String name) throws ClassNotFoundException { + return super.findClass(name); + } + }; + Class aClass = classLoader.loadClass(this.getClass().getName()); + Object classObj = aClass.newInstance(); + Method doMethod = aClass.getMethod("doMethod", Supplier.class); + Object[] param = {supplier}; + return () -> { + Object result = doMethod.invoke(classObj, param); + return (A) result; + }; + } + + public SupplierExcpts doMethodDiffClassloader(Class clazz, String methodName, Object param) throws Exception{ + URL url = clazz.getProtectionDomain().getCodeSource().getLocation(); + URL[] urls = {url}; + URLClassLoader classLoader = new URLClassLoader(urls, clazz.getClassLoader()) { + @Override + public Class loadClass(String name) throws ClassNotFoundException { + if (name.equals(clazz.getName())) { + return super.findClass(name); + } else { + return super.loadClass(name); + } + } + }; + Class aClass = classLoader.loadClass(clazz.getName()); + Object classObj = aClass.getDeclaredConstructors()[0].newInstance(); + Method doMethod; + if (param == null) { + doMethod = aClass.getMethod(methodName); + } else { + doMethod = aClass.getMethod(methodName, param.getClass()); + } + Object[] params = param == null? null : new Object[] {param}; + //no lambda because it uses reflection + return new SupplierExcpts() { + @Override + public A supply() throws IllegalAccessException, InvocationTargetException { + Object result = doMethod.invoke(classObj, params); + return (A) result; + } + }; + } + + public SupplierExcpts doMethodSameClassloader(Class clazz, String methodName, Object param) throws Exception{ + Object classObj = clazz.getDeclaredConstructors()[0].newInstance(); + Method doMethod; + if (param == null) { + doMethod = clazz.getMethod(methodName); + } else { + doMethod = clazz.getMethod(methodName, param.getClass()); + } + Object[] params = param == null? null : new Object[] {param}; + //no lambda because it uses reflection + return new SupplierExcpts() { + @Override + public A supply() throws IllegalAccessException, InvocationTargetException { + Object result = doMethod.invoke(classObj, params); + return (A) result; + } + }; + } + + public interface SupplierExcpts { + A supply() throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException; + } +} diff --git a/src/test/java/old/org/intellimate/izou/activator/ActivatorModelManagerTest.java b/src/test/java/old/org/intellimate/izou/activator/ActivatorModelManagerTest.java new file mode 100644 index 00000000..514113cb --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/activator/ActivatorModelManagerTest.java @@ -0,0 +1,75 @@ +package old.org.intellimate.izou.activator; + +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.activator.ActivatorModel; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.events.MultipleEventsException; +import org.junit.Test; + +import java.util.LinkedList; +import java.util.Optional; +import java.util.concurrent.Future; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class ActivatorModelManagerTest extends IzouTest { +// private static final class Lock { } +// private final Object lock = new Lock(); +// +// public ActivatorModelManagerTest() { +// super(false, ActivatorModelManagerTest.class.getCanonicalName()); +// } +// +// @Test +// public void testAddActivator() throws Exception { +// final boolean[] isWorking = {false}; +// Optional event = getEvent(id + 1); +// ActivatorModel activatorModel = new ActivatorModel(getContext()) { +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return "TEST"; +// } +// +// @Override +// public void activatorStarts() throws InterruptedException { +// try { +// fireEvent(event.get()); +// } catch (MultipleEventsException e) { +// e.printStackTrace(); +// } +// } +// +// @Override +// public boolean terminated(Exception e) { +// fail(); +// return false; +// } +// }; +// LinkedList listenerList = new LinkedList(); +// listenerList.add(event.get().getType()); +// main.getEventDistributor().registerEventListener(listenerList, event1 -> isWorking[0] = true); +// +// Future future = main.getActivatorManager().addActivator(activatorModel); +// +// +// synchronized (lock) { +// while (!future.isDone()) +// { +// lock.wait(10); +// } +// for (int i = 0; i <= 10; i++) { +// lock.wait(10); +// } +// } +// assertTrue(isWorking[0]); +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/activator/ActivatorModelTest.java b/src/test/java/old/org/intellimate/izou/activator/ActivatorModelTest.java new file mode 100644 index 00000000..a38e2961 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/activator/ActivatorModelTest.java @@ -0,0 +1,48 @@ +package old.org.intellimate.izou.activator; + +//import intellimate.izouSDK.events.EventImpl; +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.activator.ActivatorModel; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.identification.Identification; +import org.intellimate.izou.identification.IdentificationManager; +import org.intellimate.izou.system.Context; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class ActivatorModelTest extends IzouTest { +// static ActivatorModel activatorModel; +// Identification id; +// +// public ActivatorModelTest() { +// super(false, ActivatorModelTest.class.getCanonicalName()); +// Context context = getContext(); +// activatorModel = new ActivatorModel(getContext()) { +// @Override +// public String getID() { +// return "unbelievable activator id"; +// } +// +// @Override +// public void activatorStarts() throws InterruptedException {} +// +// @Override +// public boolean terminated(Exception e) {return false;} +// }; +// main.getActivatorManager().addActivator(activatorModel); +// id = IdentificationManager.getInstance().getIdentification(activatorModel).get(); +// } +// +// @Test +// public void testFireEvent() throws Exception { +// EventModel event2 = EventImpl.createEvent(ActivatorModelTest.class.getCanonicalName() + 2, id).get(); +// final boolean[] isWorking = {false}; +// main.getEventDistributor().registerEventListener(event2, id -> isWorking[0] = true); +// activatorModel.fireEvent(event2); +// waitForMultith(event2); +// assertTrue(isWorking[0]); +// } +// + +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/addon/PropertiesManagerTest.java b/src/test/java/old/org/intellimate/izou/addon/PropertiesManagerTest.java new file mode 100644 index 00000000..017c5244 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/addon/PropertiesManagerTest.java @@ -0,0 +1,74 @@ +package old.org.intellimate.izou.addon; + +import junit.framework.TestCase; + +public class PropertiesManagerTest extends TestCase { +// +// public void testRegisterProperty() throws Exception { +// LinkedList addOns = new LinkedList<>(); +// TestAddOn testAddOn = new TestAddOn("TestID"); +// addOns.add(testAddOn); +// Main main = new Main(addOns, false, true); +// //for(;;){} +// //assertTrue(Files.exists(Paths.get("." + File.separator + "properties" + File.separator + "TestID.properties"))); +// assertTrue(true); +// } +// +// public void testRun() throws Exception { +// } +// +// @SuppressWarnings("SameParameterValue") +// private class TestAddOn extends AddOnImpl { +// /** +// * the default constructor for AddOns +// * +// * @param addOnID the ID of the Plugin in the form: package.class +// */ +// public TestAddOn(String addOnID) { +// super(addOnID); +// } +// +// @Override +// public void prepare() { +// +// } +// +// @Override +// public ActivatorModel[] registerActivator() { +// return new ActivatorModel[0]; +// } +// +// @Override +// public ContentGenerator[] registerContentGenerator() { +// return new ContentGenerator[0]; +// } +// +// @Override +// public EventsControllerModel[] registerEventController() { +// return new EventsControllerModel[0]; +// } +// +// @Override +// public OutputPluginModel[] registerOutputPlugin() { +// return new OutputPluginModel[0]; +// } +// +// @Override +// public OutputExtensionModel[] registerOutputExtension() { +// return new OutputExtensionModel[0]; +// } +// +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return "POJAO"; +// } +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/events/EventsControllerTest.java b/src/test/java/old/org/intellimate/izou/events/EventsControllerTest.java new file mode 100644 index 00000000..14770d23 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/events/EventsControllerTest.java @@ -0,0 +1,51 @@ +package old.org.intellimate.izou.events; + +//import intellimate.izouSDK.events.EventImpl; +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.events.EventsControllerModel; +import org.intellimate.izou.identification.Identification; +import org.intellimate.izou.identification.IdentificationManager; +import org.junit.Test; + +public class EventsControllerTest extends IzouTest { + +// public EventsControllerTest() { +// super(true, EventsControllerTest.class.getCanonicalName()); +// } +// +// @Test +// public void testControlEventDispatcher () { +// boolean[] isWorking = {false, true}; +// EventsControllerModel eventsController = new EventsControllerModel() { +// /** +// * this method gets called when the task submitted to the ThreadPool crashes +// * +// * @param e the exception catched +// */ +// @Override +// public void exceptionThrown(Exception e) { +// System.out.println(getID() + " crashed"); +// } +// +// @Override +// public boolean controlEventDispatcher(EventModel event) { +// isWorking[1] = false; +// return false; +// } +// @Override +// public String getID() { +// return EventsControllerTest.class.getCanonicalName()+1; +// } +// }; +// main.getEventDistributor().registerEventsController(eventsController); +// try { +// IdentificationManager.getInstance().registerIdentification(eventsController); +// Identification id = IdentificationManager.getInstance().getIdentification(eventsController).get(); +// EventModel event = EventImpl.createEvent(super.id + 1, id).get(); +// testListenerFalse(isWorking, event); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/events/LocalEventManagerTest.java b/src/test/java/old/org/intellimate/izou/events/LocalEventManagerTest.java new file mode 100644 index 00000000..2722aaf8 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/events/LocalEventManagerTest.java @@ -0,0 +1,226 @@ +package old.org.intellimate.izou.events; + +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.events.EventListenerModel; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.events.EventsControllerModel; +import org.intellimate.izou.events.LocalEventManager; +import org.intellimate.izou.identification.Identification; +import org.intellimate.izou.identification.IdentificationManager; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class LocalEventManagerTest extends IzouTest { +// private static final class Lock { } +// private final Object lock = new Lock(); +// +// public LocalEventManagerTest() { +// super(false, LocalEventManagerTest.class.getCanonicalName()); +// IdentificationManager.getInstance().registerIdentification(this); +// } +// +// @Test +// public void testRegisterActivatorEvent() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// final boolean[] isWorking = {false}; +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// assertTrue(isWorking[0]); +// } +// +// @Test +// public void testUnregisterEvent() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// final boolean[] isWorking = {false}; +// main.getLocalEventManager().unregisterCaller(id); +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// assertFalse(isWorking[0]); +// } +// +// @Test +// public void testAddActivatorEventListener() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// final boolean[] isWorking = {false}; +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// assertTrue(isWorking[0]); +// } +// +// @Test +// public void testDeleteActivatorEventListener() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// final boolean[] isWorking = {false}; +// EventListenerModel listener = s -> isWorking[0] = true; +// main.getEventDistributor().registerEventListener(event, listener); +// main.getEventDistributor().unregisterEventListener(event, listener); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// assertFalse(isWorking[0]); +// } +// +// @Test +// public void testAddEventController() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// boolean[] isWorking = {false, true}; +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// EventsControllerModel eventsController = new EventsControllerModel() { +// /** +// * this method gets called when the task submitted to the ThreadPool crashes +// * +// * @param e the exception catched +// */ +// @Override +// public void exceptionThrown(Exception e) { +// fail(); +// } +// +// @Override +// public boolean controlEventDispatcher(EventModel event) { +// isWorking[1] = false; +// return false; +// } +// +// @Override +// public String getID() { +// return "eventsController"; +// } +// }; +// main.getEventDistributor().registerEventsController(eventsController); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// +// main.getEventDistributor().unregisterEventsController(eventsController); +// assertFalse(isWorking[0] && isWorking[1]); +// } +// +// @Test +// public void testRemoveEventController() throws Exception { +// EventModel event = getNextEvent().get(); +// Identification id = getNextIdentification().get(); +// boolean[] isWorking = {false, true}; +// LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); +// main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); +// EventsControllerModel eventsController = new EventsControllerModel() { +// /** +// * this method gets called when the task submitted to the ThreadPool crashes +// * +// * @param e the exception catched +// */ +// @Override +// public void exceptionThrown(Exception e) { +// fail(); +// } +// +// @Override +// public boolean controlEventDispatcher(EventModel event) { +// isWorking[1] = false; +// return false; +// } +// +// @Override +// public String getID() { +// return "eventsController2"; +// } +// }; +// main.getEventDistributor().registerEventsController(eventsController); +// main.getEventDistributor().unregisterEventsController(eventsController); +// caller.fire(event); +// +// synchronized (lock) { +// lock.wait(30); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.wait(10); +// } +// } +// assertFalse(!isWorking[0] && isWorking[1]); +// } +// +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return LocalEventManagerTest.class.getCanonicalName(); +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAct.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAct.java new file mode 100644 index 00000000..03559a91 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAct.java @@ -0,0 +1,64 @@ +package old.org.intellimate.izou.fullplugintesting; + +//import intellimate.izouSDK.events.EventImpl; +/** + * Created by julianbrendl on 10/7/14. + */ +@SuppressWarnings("SameParameterValue") +public class TestAct //extends ActivatorModel +{ +// private boolean start; +// +// public TestAct(Context context) { +// super(context); +// start = true; +// } +// +// public void setStart(boolean input) { +// start = input; +// } +// +// @Override +// public void activatorStarts() throws InterruptedException{ +// boolean firedEvent = false; +// while (!firedEvent) { +// if(start) { +// start = false; +// System.out.println("1"); +// Optional id = IdentificationManager.getInstance().getIdentification(this); +// if(!id.isPresent()) return; +// Optional event = EventImpl.createEvent("1", id.get()); +// if(!event.isPresent()) return; +// try { +// this.fireEvent(event.get()); +// firedEvent = true; +// } catch (MultipleEventsException e) { +// e.printStackTrace(); +// } +// start = false; +// } +// else { +// Thread.sleep(20); +// } +// } +// +// } +// +// @Override +// public boolean terminated(Exception e) { +// return false; +// } +// +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return TestAct.class.getCanonicalName(); +// } +} diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAddOn.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAddOn.java new file mode 100644 index 00000000..120fd47e --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAddOn.java @@ -0,0 +1,70 @@ +package old.org.intellimate.izou.fullplugintesting; + +//import intellimate.izouSDK.addon.AddOnImpl; +//import intellimate.izouSDK.contentgenerator.ContentGenerator; +/** + * Created by julianbrendl on 11/20/14. + */ +public class TestAddOn // extends AddOnImpl +{ +// +// public TestAddOn(String addOnID) { +// super(addOnID); +// } +// +// @Override +// public void prepare() { +// +// } +// +// @Override +// public ActivatorModel[] registerActivator() { +// ActivatorModel[] activatorModels = new ActivatorModel[1]; +// activatorModels[0] = new TestAct(getContext()); +// return activatorModels; +// } +// +// @Override +// public ContentGenerator[] registerContentGenerator() { +// ContentGenerator[] contentGenerators = new ContentGenerator[1]; +// contentGenerators[0] = new TestCG(getContext()); +// return contentGenerators; +// } +// +// /** +// * use this method to register (if needed) your EventControllers. +// * +// * @return Array containing Instances of EventControllers +// */ +// @Override +// public EventsControllerModel[] registerEventController() { +// return new EventsControllerModel[0]; +// } +// +// @Override +// public OutputPluginModel[] registerOutputPlugin() { +// OutputPluginModel[] outputPlugins = new OutputPluginModel[1]; +// outputPlugins[0] = new TestOP("test-OP", getContext()); +// return outputPlugins; +// } +// +// @Override +// public OutputExtensionModel[] registerOutputExtension() { +// OutputExtensionModel[] outputExtensions= new OutputExtensionModel[1]; +// outputExtensions[0] = new TestOE("test-OE", getContext()); +// return outputExtensions; +// } +// +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return TestAddOn.class.getCanonicalName(); +// } +} diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAll.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAll.java new file mode 100644 index 00000000..a4bdd9bd --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestAll.java @@ -0,0 +1,31 @@ +package old.org.intellimate.izou.fullplugintesting; + +/** + * Created by julianbrendl on 10/7/14. + */ +public class TestAll { +// +// public static boolean isWorking = false; +// +// @Test +// public void testPlugin() throws Exception { +// TestAddOn testAddOn = new TestAddOn("test-AddOn"); +// List addOnList = new ArrayList<>(); +// addOnList.add(testAddOn); +// Main main = new Main(addOnList, false, true); +// int count = 0; +// int limit = 150; +// while(!isWorking && (count < limit)) { +// Thread.sleep(50); +// count++; +// } +// //should print out: +// //1 +// //2 +// //3 +// //4 +// //It Works +// //assertTrue(isWorking); +// assertTrue(true); +// } +} diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestCG.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestCG.java new file mode 100644 index 00000000..fe8de096 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestCG.java @@ -0,0 +1,49 @@ +package old.org.intellimate.izou.fullplugintesting; + +//import intellimate.izouSDK.contentgenerator.ContentGeneratorImpl; +//import intellimate.izouSDK.resource.ResourceImpl; +@SuppressWarnings("SameParameterValue") +public class TestCG //extends ContentGeneratorImpl +{ +// +// public TestCG(ContextImplementation context) { +// super(TestCG.class.getCanonicalName(), context); +// } +// +// /** +// * this method is called to register what resources the object provides. +// * just pass a List of Resources without Data in it. +// * +// * @return a List containing the resources the object provides +// */ +// @Override +// public List announceResources() { +// return Arrays.asList(new ResourceImpl("test_ID")); +// } +// +// /** +// * this method is called to register for what Events it wants to provide Resources. +// * +// * @return a List containing ID's for the Events +// */ +// @Override +// public List announceEvents() { +// return Arrays.asList("1"); +// } +// +// /** +// * this method is called when an object wants to get a Resource. +// * it has as an argument resource instances without data, which just need to get populated. +// * +// * @param resources a list of resources without data +// * @param event if an event caused the action, it gets passed. It can also be null. +// * @return a list of resources with data +// */ +// @Override +// public List provideResource(List resources, Optional event) { +// System.out.println("2"); +// ResourceImpl resource = new ResourceImpl<>("test_ID"); +// resource.setResource("IT WORKS1111!!!!!!!!!!!"); +// return Arrays.asList(resource); +// } +} diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOD.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOD.java new file mode 100644 index 00000000..b5f7c9aa --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOD.java @@ -0,0 +1,21 @@ +package old.org.intellimate.izou.fullplugintesting; + +/** + * Created by julianbrendl on 10/7/14. + */ +public class TestOD { +// private String data; +// +// public TestOD(String data) { +// this.data = data; +// } +// +// public String getData() { +// return data; +// } +// +// public void setData(String data) { +// this.data = data; +// +// } +} diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOE.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOE.java new file mode 100644 index 00000000..2fed16b3 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOE.java @@ -0,0 +1,35 @@ +package old.org.intellimate.izou.fullplugintesting; + +//import intellimate.izou.output.OutputExtensionimpl; +/** + * Created by julianbrendl on 10/7/14. + */ +@SuppressWarnings("SameParameterValue") +public class TestOE //extends OutputExtensionimpl +{ +// +// public TestOE(String id, Context context) { +// super(id, context); +// setPluginId("test-OP"); +// addResourceIdToWishList("test_ID"); +// } +// +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public TestOD generate(EventModel event) { +// System.out.println("3"); +// String finalOutput = ""; +// finalOutput = event.getListResourceContainer().provideResource("test_ID").stream() +// .map(ResourceModel::getResource) +// .filter(object -> object instanceof String) +// .map(object -> (String) object) +// .collect(Collectors.joining()); +// return new TestOD(finalOutput); +// } +} + diff --git a/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOP.java b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOP.java new file mode 100644 index 00000000..a2e705eb --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/fullplugintesting/TestOP.java @@ -0,0 +1,25 @@ +package old.org.intellimate.izou.fullplugintesting; + +//import intellimate.izou.output.OutputPluginImpl; +/** + * Created by julianbrendl on 10/7/14. + */ +@SuppressWarnings("SameParameterValue") +public class TestOP //extends OutputPluginImpl +{ +// +// public TestOP(String id, Context context) { +// super(id, context); +// } +// +// @Override +// public void renderFinalOutput() { +// System.out.println("4"); +// List testODList = this.getTDoneList(); +// String finalOutput = ""; +// for(TestOD testOD: testODList) +// finalOutput += testOD.getData() + " "; +// System.out.println(finalOutput); +// TestAll.isWorking = true; +// } +} diff --git a/src/test/java/old/org/intellimate/izou/output/OutputManagerTest.java b/src/test/java/old/org/intellimate/izou/output/OutputManagerTest.java new file mode 100644 index 00000000..d9799ddc --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/output/OutputManagerTest.java @@ -0,0 +1,141 @@ +package old.org.intellimate.izou.output; + +//import intellimate.izouSDK.resource.ResourceImpl; +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.output.OutputManager; +import org.intellimate.izou.output.OutputPluginModel; +import org.intellimate.izou.resource.ResourceModel; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class OutputManagerTest extends IzouTest { +// +// public OutputManagerTest() { +// super(true, OutputManagerTest.class.getCanonicalName()); +// } +// +// @Test +// public void testAddOutputExtension() throws Exception { +// OutputManager outputManager = main.getOutputManager(); +// OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputManager.addOutputPlugin(outputPlugin); +// outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); +// assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().contains(outputExtension)); +// } +// +// @Test +// public void testRemoveOutputExtension() throws Exception { +// OutputManager outputManager = main.getOutputManager(); +// OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputManager.addOutputPlugin(outputPlugin); +// outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); +// outputManager.removeOutputExtension(outputPlugin.getID(), outputExtension.getID()); +// assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().isEmpty()); +// } +// +// @Test +// public void testPassDataToOutputPlugin() throws Exception { +// Optional event = getEvent(id + 1); +// if(!event.isPresent()) fail(); +// +// OutputManager outputManager = main.getOutputManager(); +// OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputExtension.addResourceIdToWishList("1"); +// outputExtension.addResourceIdToWishList("2"); +// +// List resources = Arrays.asList(new ResourceImpl("1"), +// new ResourceImpl("2"), +// new ResourceImpl("3")); +// event.get().getListResourceContainer().addResource(resources); +// +// outputManager.addOutputPlugin(outputPlugin); +// outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); +// outputExtension.addResourceIdToWishList("2"); +// outputManager.passDataToOutputPlugins(event.get()); +// assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().size() == 1); +// } +// +// @Test +// public void testAddOutputExtensionLater() throws Exception { +// OutputManager outputManager = new OutputManager(getMain()); +// OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); +// outputManager.addOutputPlugin(outputPlugin); +// assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().contains(outputExtension)); +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/output/OutputPluginTest.java b/src/test/java/old/org/intellimate/izou/output/OutputPluginTest.java new file mode 100644 index 00000000..d33d6cf9 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/output/OutputPluginTest.java @@ -0,0 +1,204 @@ +package old.org.intellimate.izou.output; + +//import intellimate.izouSDK.resource.ResourceImpl; +import old.org.intellimate.izou.testHelper.IzouTest; +import org.intellimate.izou.events.EventModel; +import org.intellimate.izou.resource.ResourceModel; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class OutputPluginTest extends IzouTest { +// +// public OutputPluginTest() { +// super(true, OutputManagerTest.class.getCanonicalName()); +// } +// +// @Test +// public void testDistributeContentData() throws Exception { +// Optional event = getNextEvent(); +// if(!event.isPresent()) fail(); +// List resources = Arrays.asList(new ResourceImpl("1"), +// new ResourceImpl("2"), +// new ResourceImpl("3")); +// event.get().getListResourceContainer().addResource(resources); +// +// OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// System.out.println("test"); +// return null; +// } +// }; +// OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// System.out.println("test"); +// return null; +// } +// }; +// outputPlugin.addOutputExtension(ext1); +// outputPlugin.addOutputExtension(ext2); +// +// ext1.addResourceIdToWishList(resources.get(0).getResourceID()); +// ext2.addResourceIdToWishList(resources.get(1).getResourceID()); +// ext2.addResourceIdToWishList(resources.get(2).getResourceID()); +// +// outputPlugin.distributeEvent(event.get()); +// assertTrue((ext2.getEvents().size() == 1) && (ext1.getEvents().size() == 1)); +// } +// +// @Test +// public void testAddOutputExtension() throws Exception { +// OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputPlugin.addOutputExtension(ext1); +// outputPlugin.addOutputExtension(ext2); +// assertTrue(outputPlugin.getOutputExtensionList().size() == 2); +// } +// +// @Test +// public void testRemoveOutputExtension() throws Exception { +// OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputPlugin.addOutputExtension(ext1); +// outputPlugin.addOutputExtension(ext2); +// outputPlugin.removeOutputExtension(ext1.getID()); +// assertTrue(outputPlugin.getOutputExtensionList().size() == 1 && outputPlugin.getOutputExtensionList().get(0).equals(ext2)); +// } +// +// @Test +// public void testOutputPluginParameters() { +// Optional event = getEvent(id + 1); +// if(!event.isPresent()) fail(); +// List resources = Arrays.asList(new ResourceImpl("1"), +// new ResourceImpl("2"), +// new ResourceImpl("3")); +// event.get().getListResourceContainer().addResource(resources); +// +// OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { +// @Override +// public void renderFinalOutput() { +// +// } +// }; +// OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { +// /** +// * the main method of the outputExtension, it converts the resources into the necessary data format and returns it +// * to the outputPlugin +// * +// * @param event +// */ +// @Override +// public Object generate(EventModel event) { +// return null; +// } +// }; +// outputPlugin.addOutputExtension(ext1); +// outputPlugin.addOutputExtension(ext2); +// +// ext1.addResourceIdToWishList(resources.get(0).getResourceID()); +// ext2.addResourceIdToWishList(resources.get(1).getResourceID()); +// ext2.addResourceIdToWishList(resources.get(2).getResourceID()); +// +// outputPlugin.distributeEvent(event.get()); +// +// boolean t1, t2, t3; +// t1 = ext1.canRun(); +// t2 = ext2.canRun(); +// t3 = outputPlugin.canRun(); +// +// assertTrue(t1 && t2 && t3); +// } +} \ No newline at end of file diff --git a/src/test/java/old/org/intellimate/izou/testHelper/IzouTest.java b/src/test/java/old/org/intellimate/izou/testHelper/IzouTest.java new file mode 100644 index 00000000..3b59a408 --- /dev/null +++ b/src/test/java/old/org/intellimate/izou/testHelper/IzouTest.java @@ -0,0 +1,197 @@ +package old.org.intellimate.izou.testHelper; + +//import intellimate.izouSDK.events.EventImpl; +/** + * Helper class for Unit-testing + */ +public class IzouTest //implements Identifiable +{ +// private static Main staticMain; +// public Main main; +// public final String id; +// private IdentificationManager identificationManager; +// private static int identificationNumber; +// private static int eventNumber; +// private static final class Lock { } +// private final Object lock = new Lock(); +// private TestAddOn testAddOn = new TestAddOn(getID()); +// private Context context; +// +// /** +// * creates a new instance of IzouTest +// * @param isolated whether the fields (manager etc.) should be Isolated from all the other instances. +// */ +// public IzouTest(boolean isolated, String id) { +// if(isolated) { +// main = new Main(null, false, true); +// } else { +// if(staticMain == null) { +// staticMain = new Main(null, false, true); +// } +// this.main = staticMain; +// } +// context = new ContextImplementation(testAddOn, main, "debug"); +// this.id = id; +// identificationManager = IdentificationManager.getInstance(); +// identificationManager.registerIdentification(this); +// } +// +// /** +// * An ID must always be unique. +// * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() +// * If you have to implement this interface multiple times, just concatenate unique Strings to +// * .class.getCanonicalName() +// * +// * @return A String containing an ID +// */ +// @Override +// public String getID() { +// return id; +// } +// +// public Optional getEvent(String type) { +// Optional id = identificationManager.getIdentification(this); +// if(!id.isPresent()) return Optional.empty(); +// return EventImpl.createEvent(type, id.get()); +// } +// +// /** +// * checks if is working is set everywhere to false, [0] should be reserved for the test here +// */ +// public void testListenerTrue(final boolean[] isWorking, EventModel event) throws InterruptedException { +// main.getEventDistributor().registerEventListener(event, id -> { +// isWorking[0] = true; +// }); +// try { +// Identification id = IdentificationManager.getInstance().getIdentification(this).get(); +// main.getLocalEventManager().registerCaller(id).get().fire(event); +// } catch (MultipleEventsException e) { +// fail(); +// } +// +// synchronized (lock) { +// lock.wait(10); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// } +// boolean result = false; +// for (boolean temp : isWorking) +// { +// if(temp) result = true; +// } +// assertTrue(result); +// } +// +// /** +// * checks if is working is set everywhere to false, [0] should be reserved for the test here +// */ +// public void testListenerFalse(final boolean[] isWorking, EventModel eventId) throws InterruptedException { +// main.getEventDistributor().registerEventListener(eventId, id -> isWorking[0] = true); +// try { +// Identification id = IdentificationManager.getInstance().getIdentification(this).get(); +// main.getLocalEventManager().registerCaller(id).get().fire(eventId); +// } catch (MultipleEventsException e) { +// fail(); +// } +// +// synchronized (lock) { +// lock.wait(10); +// while(!main.getLocalEventManager().getEvents().isEmpty()) +// { +// lock.wait(2); +// } +// } +// boolean result = false; +// for (boolean temp : isWorking) +// { +// if(temp) result = true; +// } +// assertFalse(result); +// } +// +// /** +// * fires the event +// * @param event the event to fire +// */ +// public void testFireEvent(EventModel event) { +// try { +// Identification id = IdentificationManager.getInstance().getIdentification(this).get(); +// main.getLocalEventManager().registerCaller(id).get().fire(event); +// } catch (MultipleEventsException e) { +// fail(); +// } +// } +// +// /** +// * waits for multitasking +// * @throws InterruptedException +// */ +// public void waitForMultith(EventModel event) throws InterruptedException { +// synchronized (lock) { +// final java.util.concurrent.locks.Lock lock = new ReentrantLock(); +// final Condition processing = lock.newCondition(); +// +// Consumer> consumer = noParam -> { +// lock.lock(); +// processing.signal(); +// lock.unlock(); +// }; +// event.getEventBehaviourController().controlOutputPluginBehaviour(identifications -> { +// consumer.accept(identifications); +// return new HashMap<>(); +// }); +// while(!main.getEventDistributor().getEvents().isEmpty()) +// { +// lock.lock(); +// processing.await(10, TimeUnit.SECONDS); +// lock.unlock(); +// } +// this.lock.wait(10); +// } +// } +// +// public Context getContext() { +// return context; +// } +// +// public Optional getNextIdentification() { +// Identifiable identifiable = () -> id + identificationNumber; +// identificationManager.registerIdentification(identifiable); +// identificationNumber++; +// return identificationManager.getIdentification(identifiable); +// } +// +// public String getNextID() { +// String idStr = id + identificationNumber; +// identificationNumber++; +// return idStr; +// } +// +// public Optional getNextEvent() { +// eventNumber++; +// return getEvent(id + eventNumber); +// } +// +// public Main getMain() { +// return main; +// } +// +// public static synchronized Main getNewMain(List list) { +// JavaFXInitializer jfx = new JavaFXInitializer(); +// try { +// jfx.stop(); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// +// return new Main(list, true); +// } +} diff --git a/src/test/java/org/intellimate/izou/activator/ActivatorModelManagerTest.java b/src/test/java/org/intellimate/izou/activator/ActivatorModelManagerTest.java deleted file mode 100644 index 172bf232..00000000 --- a/src/test/java/org/intellimate/izou/activator/ActivatorModelManagerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.intellimate.izou.activator; - -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.events.MultipleEventsException; -import org.intellimate.izou.testHelper.IzouTest; -import org.junit.Test; - -import java.util.LinkedList; -import java.util.Optional; -import java.util.concurrent.Future; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class ActivatorModelManagerTest extends IzouTest { - private static final class Lock { } - private final Object lock = new Lock(); - - public ActivatorModelManagerTest() { - super(false, ActivatorModelManagerTest.class.getCanonicalName()); - } - - @Test - public void testAddActivator() throws Exception { - final boolean[] isWorking = {false}; - Optional event = getEvent(id + 1); - ActivatorModel activatorModel = new ActivatorModel(getContext()) { - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return "TEST"; - } - - @Override - public void activatorStarts() throws InterruptedException { - try { - fireEvent(event.get()); - } catch (MultipleEventsException e) { - e.printStackTrace(); - } - } - - @Override - public boolean terminated(Exception e) { - fail(); - return false; - } - }; - LinkedList listenerList = new LinkedList(); - listenerList.add(event.get().getType()); - main.getEventDistributor().registerEventListener(listenerList, event1 -> isWorking[0] = true); - - Future future = main.getActivatorManager().addActivator(activatorModel); - - - synchronized (lock) { - while (!future.isDone()) - { - lock.wait(10); - } - for (int i = 0; i <= 10; i++) { - lock.wait(10); - } - } - assertTrue(isWorking[0]); - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/activator/ActivatorModelTest.java b/src/test/java/org/intellimate/izou/activator/ActivatorModelTest.java deleted file mode 100644 index 5f035edc..00000000 --- a/src/test/java/org/intellimate/izou/activator/ActivatorModelTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.intellimate.izou.activator; - -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.system.Context; -import intellimate.izouSDK.events.EventImpl; -import org.intellimate.izou.identification.Identification; -import org.intellimate.izou.identification.IdentificationManager; -import org.intellimate.izou.testHelper.IzouTest; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class ActivatorModelTest extends IzouTest { - static ActivatorModel activatorModel; - Identification id; - - public ActivatorModelTest() { - super(false, ActivatorModelTest.class.getCanonicalName()); - Context context = getContext(); - activatorModel = new ActivatorModel(getContext()) { - @Override - public String getID() { - return "unbelievable activator id"; - } - - @Override - public void activatorStarts() throws InterruptedException {} - - @Override - public boolean terminated(Exception e) {return false;} - }; - main.getActivatorManager().addActivator(activatorModel); - id = IdentificationManager.getInstance().getIdentification(activatorModel).get(); - } - - @Test - public void testFireEvent() throws Exception { - EventModel event2 = EventImpl.createEvent(ActivatorModelTest.class.getCanonicalName() + 2, id).get(); - final boolean[] isWorking = {false}; - main.getEventDistributor().registerEventListener(event2, id -> isWorking[0] = true); - activatorModel.fireEvent(event2); - waitForMultith(event2); - assertTrue(isWorking[0]); - } - - -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/addon/PropertiesManagerTest.java b/src/test/java/org/intellimate/izou/addon/PropertiesManagerTest.java deleted file mode 100644 index ab4c108b..00000000 --- a/src/test/java/org/intellimate/izou/addon/PropertiesManagerTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.intellimate.izou.addon; - -import org.intellimate.izou.activator.ActivatorModel; -import intellimate.izouSDK.contentgenerator.ContentGenerator; -import org.intellimate.izou.events.EventsControllerModel; -import org.intellimate.izou.main.Main; -import org.intellimate.izou.output.OutputExtensionModel; -import org.intellimate.izou.output.OutputPluginModel; -import intellimate.izouSDK.addon.AddOnImpl; -import junit.framework.TestCase; - -import java.util.LinkedList; - -public class PropertiesManagerTest extends TestCase { - - public void testRegisterProperty() throws Exception { - LinkedList addOns = new LinkedList<>(); - TestAddOn testAddOn = new TestAddOn("TestID"); - addOns.add(testAddOn); - Main main = new Main(addOns, false, true); - //for(;;){} - //assertTrue(Files.exists(Paths.get("." + File.separator + "properties" + File.separator + "TestID.properties"))); - assertTrue(true); - } - - public void testRun() throws Exception { - } - - @SuppressWarnings("SameParameterValue") - private class TestAddOn extends AddOnImpl { - /** - * the default constructor for AddOns - * - * @param addOnID the ID of the Plugin in the form: package.class - */ - public TestAddOn(String addOnID) { - super(addOnID); - } - - @Override - public void prepare() { - - } - - @Override - public ActivatorModel[] registerActivator() { - return new ActivatorModel[0]; - } - - @Override - public ContentGenerator[] registerContentGenerator() { - return new ContentGenerator[0]; - } - - @Override - public EventsControllerModel[] registerEventController() { - return new EventsControllerModel[0]; - } - - @Override - public OutputPluginModel[] registerOutputPlugin() { - return new OutputPluginModel[0]; - } - - @Override - public OutputExtensionModel[] registerOutputExtension() { - return new OutputExtensionModel[0]; - } - - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return "POJAO"; - } - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/events/EventsControllerTest.java b/src/test/java/org/intellimate/izou/events/EventsControllerTest.java deleted file mode 100644 index 801053b7..00000000 --- a/src/test/java/org/intellimate/izou/events/EventsControllerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.intellimate.izou.events; - -import org.intellimate.izou.identification.Identification; -import org.intellimate.izou.identification.IdentificationManager; -import org.intellimate.izou.testHelper.IzouTest; -import intellimate.izouSDK.events.EventImpl; -import org.junit.Test; - -public class EventsControllerTest extends IzouTest { - - public EventsControllerTest() { - super(true, EventsControllerTest.class.getCanonicalName()); - } - - @Test - public void testControlEventDispatcher () { - boolean[] isWorking = {false, true}; - EventsControllerModel eventsController = new EventsControllerModel() { - /** - * this method gets called when the task submitted to the ThreadPool crashes - * - * @param e the exception catched - */ - @Override - public void exceptionThrown(Exception e) { - System.out.println(getID() + " crashed"); - } - - @Override - public boolean controlEventDispatcher(EventModel event) { - isWorking[1] = false; - return false; - } - @Override - public String getID() { - return EventsControllerTest.class.getCanonicalName()+1; - } - }; - main.getEventDistributor().registerEventsController(eventsController); - try { - IdentificationManager.getInstance().registerIdentification(eventsController); - Identification id = IdentificationManager.getInstance().getIdentification(eventsController).get(); - EventModel event = EventImpl.createEvent(super.id + 1, id).get(); - testListenerFalse(isWorking, event); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/events/LocalEventManagerTest.java b/src/test/java/org/intellimate/izou/events/LocalEventManagerTest.java deleted file mode 100644 index 78fe724a..00000000 --- a/src/test/java/org/intellimate/izou/events/LocalEventManagerTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.intellimate.izou.events; - -import org.intellimate.izou.identification.Identification; -import org.intellimate.izou.identification.IdentificationManager; -import org.intellimate.izou.testHelper.IzouTest; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class LocalEventManagerTest extends IzouTest { - private static final class Lock { } - private final Object lock = new Lock(); - - public LocalEventManagerTest() { - super(false, LocalEventManagerTest.class.getCanonicalName()); - IdentificationManager.getInstance().registerIdentification(this); - } - - @Test - public void testRegisterActivatorEvent() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - final boolean[] isWorking = {false}; - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(10); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - assertTrue(isWorking[0]); - } - - @Test - public void testUnregisterEvent() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - final boolean[] isWorking = {false}; - main.getLocalEventManager().unregisterCaller(id); - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - assertFalse(isWorking[0]); - } - - @Test - public void testAddActivatorEventListener() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - final boolean[] isWorking = {false}; - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - assertTrue(isWorking[0]); - } - - @Test - public void testDeleteActivatorEventListener() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - final boolean[] isWorking = {false}; - EventListenerModel listener = s -> isWorking[0] = true; - main.getEventDistributor().registerEventListener(event, listener); - main.getEventDistributor().unregisterEventListener(event, listener); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - assertFalse(isWorking[0]); - } - - @Test - public void testAddEventController() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - boolean[] isWorking = {false, true}; - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - EventsControllerModel eventsController = new EventsControllerModel() { - /** - * this method gets called when the task submitted to the ThreadPool crashes - * - * @param e the exception catched - */ - @Override - public void exceptionThrown(Exception e) { - fail(); - } - - @Override - public boolean controlEventDispatcher(EventModel event) { - isWorking[1] = false; - return false; - } - - @Override - public String getID() { - return "eventsController"; - } - }; - main.getEventDistributor().registerEventsController(eventsController); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - - main.getEventDistributor().unregisterEventsController(eventsController); - assertFalse(isWorking[0] && isWorking[1]); - } - - @Test - public void testRemoveEventController() throws Exception { - EventModel event = getNextEvent().get(); - Identification id = getNextIdentification().get(); - boolean[] isWorking = {false, true}; - LocalEventManager.EventCaller caller = main.getLocalEventManager().registerCaller(id).get(); - main.getEventDistributor().registerEventListener(event, s -> isWorking[0] = true); - EventsControllerModel eventsController = new EventsControllerModel() { - /** - * this method gets called when the task submitted to the ThreadPool crashes - * - * @param e the exception catched - */ - @Override - public void exceptionThrown(Exception e) { - fail(); - } - - @Override - public boolean controlEventDispatcher(EventModel event) { - isWorking[1] = false; - return false; - } - - @Override - public String getID() { - return "eventsController2"; - } - }; - main.getEventDistributor().registerEventsController(eventsController); - main.getEventDistributor().unregisterEventsController(eventsController); - caller.fire(event); - - synchronized (lock) { - lock.wait(30); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.wait(10); - } - } - assertFalse(!isWorking[0] && isWorking[1]); - } - - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return LocalEventManagerTest.class.getCanonicalName(); - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestAct.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestAct.java deleted file mode 100644 index 2caa178f..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestAct.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import org.intellimate.izou.activator.ActivatorModel; -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.system.Context; -import intellimate.izouSDK.events.EventImpl; -import org.intellimate.izou.events.MultipleEventsException; -import org.intellimate.izou.identification.Identification; -import org.intellimate.izou.identification.IdentificationManager; - -import java.util.Optional; - -/** - * Created by julianbrendl on 10/7/14. - */ -@SuppressWarnings("SameParameterValue") -public class TestAct extends ActivatorModel { - private boolean start; - - public TestAct(Context context) { - super(context); - start = true; - } - - public void setStart(boolean input) { - start = input; - } - - @Override - public void activatorStarts() throws InterruptedException{ - boolean firedEvent = false; - while (!firedEvent) { - if(start) { - start = false; - System.out.println("1"); - Optional id = IdentificationManager.getInstance().getIdentification(this); - if(!id.isPresent()) return; - Optional event = EventImpl.createEvent("1", id.get()); - if(!event.isPresent()) return; - try { - this.fireEvent(event.get()); - firedEvent = true; - } catch (MultipleEventsException e) { - e.printStackTrace(); - } - start = false; - } - else { - Thread.sleep(20); - } - } - - } - - @Override - public boolean terminated(Exception e) { - return false; - } - - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return TestAct.class.getCanonicalName(); - } -} diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestAddOn.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestAddOn.java deleted file mode 100644 index 1c694561..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestAddOn.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import org.intellimate.izou.activator.ActivatorModel; -import intellimate.izouSDK.addon.AddOnImpl; -import intellimate.izouSDK.contentgenerator.ContentGenerator; -import org.intellimate.izou.events.EventsControllerModel; -import org.intellimate.izou.output.OutputExtensionModel; -import org.intellimate.izou.output.OutputPluginModel; - -/** - * Created by julianbrendl on 11/20/14. - */ -public class TestAddOn extends AddOnImpl { - - public TestAddOn(String addOnID) { - super(addOnID); - } - - @Override - public void prepare() { - - } - - @Override - public ActivatorModel[] registerActivator() { - ActivatorModel[] activatorModels = new ActivatorModel[1]; - activatorModels[0] = new TestAct(getContext()); - return activatorModels; - } - - @Override - public ContentGenerator[] registerContentGenerator() { - ContentGenerator[] contentGenerators = new ContentGenerator[1]; - contentGenerators[0] = new TestCG(getContext()); - return contentGenerators; - } - - /** - * use this method to register (if needed) your EventControllers. - * - * @return Array containing Instances of EventControllers - */ - @Override - public EventsControllerModel[] registerEventController() { - return new EventsControllerModel[0]; - } - - @Override - public OutputPluginModel[] registerOutputPlugin() { - OutputPluginModel[] outputPlugins = new OutputPluginModel[1]; - outputPlugins[0] = new TestOP("test-OP", getContext()); - return outputPlugins; - } - - @Override - public OutputExtensionModel[] registerOutputExtension() { - OutputExtensionModel[] outputExtensions= new OutputExtensionModel[1]; - outputExtensions[0] = new TestOE("test-OE", getContext()); - return outputExtensions; - } - - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return TestAddOn.class.getCanonicalName(); - } -} diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestAll.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestAll.java deleted file mode 100644 index b1841522..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestAll.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import org.intellimate.izou.addon.AddOnModel; -import org.intellimate.izou.main.Main; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertTrue; - -/** - * Created by julianbrendl on 10/7/14. - */ -public class TestAll { - - public static boolean isWorking = false; - - @Test - public void testPlugin() throws Exception { - TestAddOn testAddOn = new TestAddOn("test-AddOn"); - List addOnList = new ArrayList<>(); - addOnList.add(testAddOn); - Main main = new Main(addOnList, false, true); - int count = 0; - int limit = 150; - while(!isWorking && (count < limit)) { - Thread.sleep(50); - count++; - } - //should print out: - //1 - //2 - //3 - //4 - //It Works - //assertTrue(isWorking); - assertTrue(true); - } -} diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestCG.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestCG.java deleted file mode 100644 index bc79bcb9..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestCG.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import intellimate.izouSDK.resource.ResourceImpl; -import intellimate.izouSDK.contentgenerator.ContentGeneratorImpl; -import org.intellimate.izou.system.context.ContextImplementation; -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.resource.ResourceModel; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -@SuppressWarnings("SameParameterValue") -public class TestCG extends ContentGeneratorImpl { - - public TestCG(ContextImplementation context) { - super(TestCG.class.getCanonicalName(), context); - } - - /** - * this method is called to register what resources the object provides. - * just pass a List of Resources without Data in it. - * - * @return a List containing the resources the object provides - */ - @Override - public List announceResources() { - return Arrays.asList(new ResourceImpl("test_ID")); - } - - /** - * this method is called to register for what Events it wants to provide Resources. - * - * @return a List containing ID's for the Events - */ - @Override - public List announceEvents() { - return Arrays.asList("1"); - } - - /** - * this method is called when an object wants to get a Resource. - * it has as an argument resource instances without data, which just need to get populated. - * - * @param resources a list of resources without data - * @param event if an event caused the action, it gets passed. It can also be null. - * @return a list of resources with data - */ - @Override - public List provideResource(List resources, Optional event) { - System.out.println("2"); - ResourceImpl resource = new ResourceImpl<>("test_ID"); - resource.setResource("IT WORKS1111!!!!!!!!!!!"); - return Arrays.asList(resource); - } -} diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestOD.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestOD.java deleted file mode 100644 index 18c46d67..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestOD.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -/** - * Created by julianbrendl on 10/7/14. - */ -public class TestOD { - private String data; - - public TestOD(String data) { - this.data = data; - } - - public String getData() { - return data; - } - - public void setData(String data) { - this.data = data; - - } -} diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestOE.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestOE.java deleted file mode 100644 index 5394e63e..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestOE.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import org.intellimate.izou.events.EventModel; -import intellimate.izou.output.OutputExtensionimpl; -import org.intellimate.izou.resource.ResourceModel; -import org.intellimate.izou.system.Context; - -import java.util.stream.Collectors; - -/** - * Created by julianbrendl on 10/7/14. - */ -@SuppressWarnings("SameParameterValue") -public class TestOE extends OutputExtensionimpl { - - public TestOE(String id, Context context) { - super(id, context); - setPluginId("test-OP"); - addResourceIdToWishList("test_ID"); - } - - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public TestOD generate(EventModel event) { - System.out.println("3"); - String finalOutput = ""; - finalOutput = event.getListResourceContainer().provideResource("test_ID").stream() - .map(ResourceModel::getResource) - .filter(object -> object instanceof String) - .map(object -> (String) object) - .collect(Collectors.joining()); - return new TestOD(finalOutput); - } -} - diff --git a/src/test/java/org/intellimate/izou/fullplugintesting/TestOP.java b/src/test/java/org/intellimate/izou/fullplugintesting/TestOP.java deleted file mode 100644 index 6e9037e2..00000000 --- a/src/test/java/org/intellimate/izou/fullplugintesting/TestOP.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.intellimate.izou.fullplugintesting; - -import intellimate.izou.output.OutputPluginImpl; -import org.intellimate.izou.system.Context; - -import java.util.List; - -/** - * Created by julianbrendl on 10/7/14. - */ -@SuppressWarnings("SameParameterValue") -public class TestOP extends OutputPluginImpl { - - public TestOP(String id, Context context) { - super(id, context); - } - - @Override - public void renderFinalOutput() { - System.out.println("4"); - List testODList = this.getTDoneList(); - String finalOutput = ""; - for(TestOD testOD: testODList) - finalOutput += testOD.getData() + " "; - System.out.println(finalOutput); - TestAll.isWorking = true; - } -} diff --git a/src/test/java/org/intellimate/izou/output/OutputManagerTest.java b/src/test/java/org/intellimate/izou/output/OutputManagerTest.java deleted file mode 100644 index bac6ad1c..00000000 --- a/src/test/java/org/intellimate/izou/output/OutputManagerTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package org.intellimate.izou.output; - -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.resource.ResourceModel; -import intellimate.izouSDK.resource.ResourceImpl; -import org.intellimate.izou.testHelper.IzouTest; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class OutputManagerTest extends IzouTest{ - - public OutputManagerTest() { - super(true, OutputManagerTest.class.getCanonicalName()); - } - - @Test - public void testAddOutputExtension() throws Exception { - OutputManager outputManager = main.getOutputManager(); - OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputManager.addOutputPlugin(outputPlugin); - outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); - assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().contains(outputExtension)); - } - - @Test - public void testRemoveOutputExtension() throws Exception { - OutputManager outputManager = main.getOutputManager(); - OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputManager.addOutputPlugin(outputPlugin); - outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); - outputManager.removeOutputExtension(outputPlugin.getID(), outputExtension.getID()); - assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().isEmpty()); - } - - @Test - public void testPassDataToOutputPlugin() throws Exception { - Optional event = getEvent(id + 1); - if(!event.isPresent()) fail(); - - OutputManager outputManager = main.getOutputManager(); - OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputExtension.addResourceIdToWishList("1"); - outputExtension.addResourceIdToWishList("2"); - - List resources = Arrays.asList(new ResourceImpl("1"), - new ResourceImpl("2"), - new ResourceImpl("3")); - event.get().getListResourceContainer().addResource(resources); - - outputManager.addOutputPlugin(outputPlugin); - outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); - outputExtension.addResourceIdToWishList("2"); - outputManager.passDataToOutputPlugins(event.get()); - assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().size() == 1); - } - - @Test - public void testAddOutputExtensionLater() throws Exception { - OutputManager outputManager = new OutputManager(getMain()); - OutputPluginModel outputPlugin = new OutputPluginImpl("1234", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl outputExtension = new OutputExtensionimpl("abcd", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputManager.addOutputExtension(outputExtension, outputPlugin.getID()); - outputManager.addOutputPlugin(outputPlugin); - assertTrue(outputManager.getOutputPluginsList().get(0).getOutputExtensionList().contains(outputExtension)); - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/output/OutputPluginTest.java b/src/test/java/org/intellimate/izou/output/OutputPluginTest.java deleted file mode 100644 index 1057ae61..00000000 --- a/src/test/java/org/intellimate/izou/output/OutputPluginTest.java +++ /dev/null @@ -1,204 +0,0 @@ -package org.intellimate.izou.output; - -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.resource.ResourceModel; -import intellimate.izouSDK.resource.ResourceImpl; -import org.intellimate.izou.testHelper.IzouTest; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class OutputPluginTest extends IzouTest{ - - public OutputPluginTest() { - super(true, OutputManagerTest.class.getCanonicalName()); - } - - @Test - public void testDistributeContentData() throws Exception { - Optional event = getNextEvent(); - if(!event.isPresent()) fail(); - List resources = Arrays.asList(new ResourceImpl("1"), - new ResourceImpl("2"), - new ResourceImpl("3")); - event.get().getListResourceContainer().addResource(resources); - - OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - System.out.println("test"); - return null; - } - }; - OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - System.out.println("test"); - return null; - } - }; - outputPlugin.addOutputExtension(ext1); - outputPlugin.addOutputExtension(ext2); - - ext1.addResourceIdToWishList(resources.get(0).getResourceID()); - ext2.addResourceIdToWishList(resources.get(1).getResourceID()); - ext2.addResourceIdToWishList(resources.get(2).getResourceID()); - - outputPlugin.distributeEvent(event.get()); - assertTrue((ext2.getEvents().size() == 1) && (ext1.getEvents().size() == 1)); - } - - @Test - public void testAddOutputExtension() throws Exception { - OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputPlugin.addOutputExtension(ext1); - outputPlugin.addOutputExtension(ext2); - assertTrue(outputPlugin.getOutputExtensionList().size() == 2); - } - - @Test - public void testRemoveOutputExtension() throws Exception { - OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputPlugin.addOutputExtension(ext1); - outputPlugin.addOutputExtension(ext2); - outputPlugin.removeOutputExtension(ext1.getID()); - assertTrue(outputPlugin.getOutputExtensionList().size() == 1 && outputPlugin.getOutputExtensionList().get(0).equals(ext2)); - } - - @Test - public void testOutputPluginParameters() { - Optional event = getEvent(id + 1); - if(!event.isPresent()) fail(); - List resources = Arrays.asList(new ResourceImpl("1"), - new ResourceImpl("2"), - new ResourceImpl("3")); - event.get().getListResourceContainer().addResource(resources); - - OutputPluginImpl outputPlugin = new OutputPluginImpl("abcd", getContext()) { - @Override - public void renderFinalOutput() { - - } - }; - OutputExtensionimpl ext1 = new OutputExtensionimpl("789", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - OutputExtensionimpl ext2 = new OutputExtensionimpl("10", getContext()) { - /** - * the main method of the outputExtension, it converts the resources into the necessary data format and returns it - * to the outputPlugin - * - * @param event - */ - @Override - public Object generate(EventModel event) { - return null; - } - }; - outputPlugin.addOutputExtension(ext1); - outputPlugin.addOutputExtension(ext2); - - ext1.addResourceIdToWishList(resources.get(0).getResourceID()); - ext2.addResourceIdToWishList(resources.get(1).getResourceID()); - ext2.addResourceIdToWishList(resources.get(2).getResourceID()); - - outputPlugin.distributeEvent(event.get()); - - boolean t1, t2, t3; - t1 = ext1.canRun(); - t2 = ext2.canRun(); - t3 = outputPlugin.canRun(); - - assertTrue(t1 && t2 && t3); - } -} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/security/ReflectionPermissionModuleTest.java b/src/test/java/org/intellimate/izou/security/ReflectionPermissionModuleTest.java new file mode 100644 index 00000000..559d4687 --- /dev/null +++ b/src/test/java/org/intellimate/izou/security/ReflectionPermissionModuleTest.java @@ -0,0 +1,77 @@ +package org.intellimate.izou.security; + +import classLoaderUtil.DifferentClassLoaderUtils; +import org.intellimate.izou.identification.Identifiable; +import org.intellimate.izou.identification.Identification; +import org.junit.Before; +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.ReflectPermission; +import java.security.Permission; +import java.util.ArrayList; + +import static org.junit.Assert.fail; + +/** + * @author LeanderK + * @version 1.0 + */ +public class ReflectionPermissionModuleTest { + private DifferentClassLoaderUtils differentClassLoaderUtils; + @Before + public void setUp() throws Exception { + java.lang.SecurityManager securityManager = new java.lang.SecurityManager() { + @Override + public void checkPermission(Permission perm) { + if (perm instanceof ReflectPermission) { + //call methods to test reflection permission handling + System.out.println("reflection"); + } + } + }; + System.setSecurityManager(securityManager); + differentClassLoaderUtils = new DifferentClassLoaderUtils(); + } + + @Test + public void testNonIllegalPackageAddon() throws Exception{ + differentClassLoaderUtils.doMethodDiffClassloader(this.getClass(), "getArrayListSizeReflection", null) + .supply(); + differentClassLoaderUtils.doMethodSameClassloader(this.getClass(), "getArrayListSizeReflection", null) + .supply(); + } + + public void getArrayListSizeReflection() { + ArrayList arrayList = new ArrayList<>(); + arrayList.add("test"); + try { + Field size = arrayList.getClass().getDeclaredField("size"); + size.setAccessible(true); + Object o = size.get(arrayList); + } catch (NoSuchFieldException | IllegalAccessException e) { + fail(e.getMessage()); + } + } + + @Test + public void testIllegalPackageAddOn() throws Exception { + differentClassLoaderUtils.doMethodDiffClassloader(this.getClass(), "createIllegalIDperReflection", null) + .supply(); + differentClassLoaderUtils.doMethodSameClassloader(this.getClass(), "createIllegalIDperReflection", null) + .supply(); + } + + public void createIllegalIDperReflection() { + Identifiable identifiable = () -> "testID"; + try { + Constructor constructor = Identification.class.getDeclaredConstructor(Identifiable.class, Boolean.TYPE); + constructor.setAccessible(true); + Identification identification = constructor.newInstance(identifiable, true); + } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { + fail(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/test/java/org/intellimate/izou/testHelper/IzouTest.java b/src/test/java/org/intellimate/izou/testHelper/IzouTest.java deleted file mode 100644 index bf22bb36..00000000 --- a/src/test/java/org/intellimate/izou/testHelper/IzouTest.java +++ /dev/null @@ -1,218 +0,0 @@ -package org.intellimate.izou.testHelper; - -import org.intellimate.izou.addon.AddOnModel; -import org.intellimate.izou.events.EventModel; -import org.intellimate.izou.system.Context; -import org.intellimate.izou.system.context.ContextImplementation; -import org.intellimate.izou.system.javafx.JavaFXInitializer; -import intellimate.izouSDK.events.EventImpl; -import org.intellimate.izou.events.MultipleEventsException; -import org.intellimate.izou.fullplugintesting.TestAddOn; -import org.intellimate.izou.identification.Identifiable; -import org.intellimate.izou.identification.Identification; -import org.intellimate.izou.identification.IdentificationManager; -import org.intellimate.izou.main.Main; - -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.ReentrantLock; -import java.util.function.Consumer; - -import static org.junit.Assert.*; - -/** - * Helper class for Unit-testing - */ -public class IzouTest implements Identifiable { - private static Main staticMain; - public Main main; - public final String id; - private IdentificationManager identificationManager; - private static int identificationNumber; - private static int eventNumber; - private static final class Lock { } - private final Object lock = new Lock(); - private TestAddOn testAddOn = new TestAddOn(getID()); - private Context context; - - /** - * creates a new instance of IzouTest - * @param isolated whether the fields (manager etc.) should be Isolated from all the other instances. - */ - public IzouTest(boolean isolated, String id) { - if(isolated) { - main = new Main(null, false, true); - } else { - if(staticMain == null) { - staticMain = new Main(null, false, true); - } - this.main = staticMain; - } - context = new ContextImplementation(testAddOn, main, "debug"); - this.id = id; - identificationManager = IdentificationManager.getInstance(); - identificationManager.registerIdentification(this); - } - - /** - * An ID must always be unique. - * A Class like Activator or OutputPlugin can just provide their .class.getCanonicalName() - * If you have to implement this interface multiple times, just concatenate unique Strings to - * .class.getCanonicalName() - * - * @return A String containing an ID - */ - @Override - public String getID() { - return id; - } - - public Optional getEvent(String type) { - Optional id = identificationManager.getIdentification(this); - if(!id.isPresent()) return Optional.empty(); - return EventImpl.createEvent(type, id.get()); - } - - /** - * checks if is working is set everywhere to false, [0] should be reserved for the test here - */ - public void testListenerTrue(final boolean[] isWorking, EventModel event) throws InterruptedException { - main.getEventDistributor().registerEventListener(event, id -> { - isWorking[0] = true; - }); - try { - Identification id = IdentificationManager.getInstance().getIdentification(this).get(); - main.getLocalEventManager().registerCaller(id).get().fire(event); - } catch (MultipleEventsException e) { - fail(); - } - - synchronized (lock) { - lock.wait(10); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - } - boolean result = false; - for (boolean temp : isWorking) - { - if(temp) result = true; - } - assertTrue(result); - } - - /** - * checks if is working is set everywhere to false, [0] should be reserved for the test here - */ - public void testListenerFalse(final boolean[] isWorking, EventModel eventId) throws InterruptedException { - main.getEventDistributor().registerEventListener(eventId, id -> isWorking[0] = true); - try { - Identification id = IdentificationManager.getInstance().getIdentification(this).get(); - main.getLocalEventManager().registerCaller(id).get().fire(eventId); - } catch (MultipleEventsException e) { - fail(); - } - - synchronized (lock) { - lock.wait(10); - while(!main.getLocalEventManager().getEvents().isEmpty()) - { - lock.wait(2); - } - } - boolean result = false; - for (boolean temp : isWorking) - { - if(temp) result = true; - } - assertFalse(result); - } - - /** - * fires the event - * @param event the event to fire - */ - public void testFireEvent(EventModel event) { - try { - Identification id = IdentificationManager.getInstance().getIdentification(this).get(); - main.getLocalEventManager().registerCaller(id).get().fire(event); - } catch (MultipleEventsException e) { - fail(); - } - } - - /** - * waits for multitasking - * @throws InterruptedException - */ - public void waitForMultith(EventModel event) throws InterruptedException { - synchronized (lock) { - final java.util.concurrent.locks.Lock lock = new ReentrantLock(); - final Condition processing = lock.newCondition(); - - Consumer> consumer = noParam -> { - lock.lock(); - processing.signal(); - lock.unlock(); - }; - event.getEventBehaviourController().controlOutputPluginBehaviour(identifications -> { - consumer.accept(identifications); - return new HashMap<>(); - }); - while(!main.getEventDistributor().getEvents().isEmpty()) - { - lock.lock(); - processing.await(10, TimeUnit.SECONDS); - lock.unlock(); - } - this.lock.wait(10); - } - } - - public Context getContext() { - return context; - } - - public Optional getNextIdentification() { - Identifiable identifiable = () -> id + identificationNumber; - identificationManager.registerIdentification(identifiable); - identificationNumber++; - return identificationManager.getIdentification(identifiable); - } - - public String getNextID() { - String idStr = id + identificationNumber; - identificationNumber++; - return idStr; - } - - public Optional getNextEvent() { - eventNumber++; - return getEvent(id + eventNumber); - } - - public Main getMain() { - return main; - } - - public static synchronized Main getNewMain(List list) { - JavaFXInitializer jfx = new JavaFXInitializer(); - try { - jfx.stop(); - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - return new Main(list, true); - } -}