@Test(dependsOnMethods={"testEffectorBodyAdded"}) public void testEntityNotPermanentlyChanged() throws Exception { EntityInternal doubler = app.createAndManageChild(EntitySpec.create(TestEntity.class)); // ensures that independent creations of the class previously modified do not have this effector Assert.assertNull( doubler.getEffector("double") ); }
Effector<T> eff2 = (Effector<T>) ((EntityInternal)entity).getEffector(eff.getName()); if (log.isTraceEnabled()) { Object eff1Body = (eff instanceof EffectorWithBody<?> ? ((EffectorWithBody<?>) eff).getBody() : "bodyless");
@Test public void testEffectorBodyAdded() throws Exception { EntityInternal doubler = app.createAndManageChild(EntitySpec.create(TestEntity.class)); // not yet present Assert.assertNull( doubler.getEffector("double") ); // add it doubler.getMutableEntityType().addEffector(DOUBLE_BODYLESS, new EffectorBody<Integer>() { @Override public Integer call(ConfigBag parameters) { int input = (Integer)parameters.getStringKey("numberToDouble"); return queue(times(input, 2)).getUnchecked(); } }); // now it is present Assert.assertNotNull( doubler.getEffector("double") ); Assert.assertEquals(doubler.invoke(DOUBLE_BODYLESS, MutableMap.of("numberToDouble", 3)).get(), (Integer)6); }
@Test public void testHappyPath() { TestEntity a = app.createAndManageChild(EntitySpec.create(TestEntity.class)); ProxyEffector proxyEffector = new ProxyEffector(ImmutableMap.of( AddEffector.EFFECTOR_NAME, "proxy-effector", ProxyEffector.TARGET_ENTITY, a, ProxyEffector.TARGET_EFFECTOR_NAME, "identityEffector")); // BasicEntity doesn't have an identityEffector. EntityInternal b = Entities.deproxy(app.createAndManageChild(EntitySpec.create(BasicEntity.class) .addInitializer(proxyEffector))); Object output = b.invoke(b.getEffector("proxy-effector"), ImmutableMap.of("arg", "value")) .getUnchecked(Duration.ONE_MINUTE); assertEquals(output, "value"); }
@Test public void testThrowsIfTargetEffectorDoesntExist() { TestEntity a = app.createAndManageChild(EntitySpec.create(TestEntity.class)); ProxyEffector proxyEffector = new ProxyEffector(ImmutableMap.of( AddEffector.EFFECTOR_NAME, "proxy-effector", ProxyEffector.TARGET_ENTITY, a, ProxyEffector.TARGET_EFFECTOR_NAME, "kajnfksjdnfkjsdnf")); EntityInternal b = Entities.deproxy(app.createAndManageChild(EntitySpec.create(BasicEntity.class) .addInitializer(proxyEffector))); try { b.invoke(b.getEffector("proxy-effector"), ImmutableMap.of("arg", "value")) .getUnchecked(Duration.ONE_MINUTE); Asserts.shouldHaveFailedPreviously("expected exception when invoking effector that does not exist"); } catch (Exception e) { Asserts.expectedFailureOfType(e, NoSuchElementException.class); } }