@Test public void testSimpleCreate() throws Exception { Foo foo = handle.attach(Foo.class); foo.insert(1, "Stephane"); Something s = foo.createBar().findById(1); assertThat(s, equalTo(new Something(1, "Stephane"))); }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { PrintWriter w = res.getWriter(); w.write(foo != null ? foo.peek() : "foo was null for peek"); filterChain.doFilter(req, res); w.write(foo != null ? foo.poke() : "foo was null for poke"); }
public void testMarshalValue() { Foo f = new Foo(); f.r1 = f.r2 = Result.FAILURE; String xml = Run.XSTREAM.toXML(f); // we should find two "FAILURE"s as they should be written out twice assertEquals(xml, 3, xml.split("FAILURE").length); }
@Test public void testHaving() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo = new Foo(); int val1 = 243342; foo.val = val1; assertEquals(1, dao.create(foo)); foo = new Foo(); foo.val = val1; assertEquals(1, dao.create(foo)); foo = new Foo(); // only one of these int val2 = 6543; foo.val = val2; assertEquals(1, dao.create(foo)); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); qb.selectColumns(Foo.VAL_COLUMN_NAME); qb.groupBy(Foo.VAL_COLUMN_NAME); qb.having("COUNT(VAL) > 1"); GenericRawResults<String[]> results = dao.queryRaw(qb.prepareStatementString()); List<String[]> list = results.getResults(); // only val2 has 2 of them assertEquals(1, list.size()); assertEquals(String.valueOf(val1), list.get(0)[0]); qb.having("COUNT(VAL) > 2"); results = dao.queryRaw(qb.prepareStatementString()); list = results.getResults(); assertEquals(0, list.size()); }
public void testSimpleTypeToken() { Foo<String, Integer> foo = new Foo<String, Integer>() {}; assertEquals(String.class, foo.getClassA()); assertEquals(Integer.class, foo.getClassB()); assertEquals(String[].class, foo.getArrayClassA()); assertEquals(Integer[].class, foo.getArrayClassB()); }
@Test public void testSerializableProxy() throws Exception { DynamicType.Loaded<Foo> loaded = instrument(Foo.class, MethodDelegation.to(SerializationCheck.class)); Foo instance = loaded.getLoaded().newInstance(); assertThat(instance.qux(), is((Object) (FOO + QUX))); }
void testWriteReadOnly(final boolean acceptWriteReadOnly) throws Exception { final Method readMethod = Foo.class.getMethod("getMyProp", null); final Foo foo = new Foo("hello"); foo.defineProperty("myProp", null, readMethod, null, ScriptableObject.EMPTY); final String script = "foo.myProp = 123; foo.myProp"; final ContextAction action = new ContextAction() { public Object run(final Context cx) { final ScriptableObject top = cx.initStandardObjects(); ScriptableObject.putProperty(top, "foo", foo); cx.evaluateString(top, script, "script", 0, null); return null; } }; final ContextFactory contextFactory = new ContextFactory() { @Override protected boolean hasFeature(final Context cx, final int featureIndex) { if (Context.FEATURE_STRICT_MODE == featureIndex) { return !acceptWriteReadOnly; } return super.hasFeature(cx, featureIndex); } }; contextFactory.call(action); }
@RequestMapping("/foo/add") @ResponseStatus(HttpStatus.CREATED) public void addFoo() { Foo foo = new Foo(); foo.name = "foobar"; fooService.addFoo(foo); }
@Test public void testDoubleDbOpen() throws Exception { clearDatabases(); ConnectionSource cs = new JdbcConnectionSource( "jdbc:h2:file:" + DATABASE_DIR + "/" + DATABASE_NAME_PREFIX + ".1"); TableUtils.createTable(cs, Foo.class); Dao<Foo, Integer> dao = Instances.getDaoManager().createDao(cs, Foo.class); Foo foo1 = new Foo(); foo1.val = 12312; assertEquals(1, dao.create(foo1)); Foo result = dao.queryForId(foo1.id); assertNotNull(result); assertEquals(foo1.val, result.val); // ================================== cs = new JdbcConnectionSource( "jdbc:h2:file:" + DATABASE_DIR + "/" + DATABASE_NAME_PREFIX + ".2"); Instances.getDaoManager().clearCache(); TableUtils.createTable(cs, Foo.class); dao = Instances.getDaoManager().createDao(cs, Foo.class); Foo foo2 = new Foo(); foo2.val = 12314; assertEquals(1, dao.create(foo2)); result = dao.queryForId(foo2.id); assertNotNull(result); assertEquals(foo2.val, result.val); }
public void testSetCoercion2() { ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("sampleBean", SampleBean.class); Serializable s = compileSetExpression("sampleBean.map2['bleh']", ctx); Foo foo = new Foo(); executeSetExpression(s, foo, "12"); assertEquals(12, foo.getSampleBean().getMap2().get("bleh").intValue()); foo = new Foo(); executeSetExpression(s, foo, "13"); assertEquals(13, foo.getSampleBean().getMap2().get("bleh").intValue()); OptimizerFactory.setDefaultOptimizer("ASM"); ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("sampleBean", SampleBean.class); s = compileSetExpression("sampleBean.map2['bleh']", ctx); foo = new Foo(); executeSetExpression(s, foo, "12"); assertEquals(12, foo.getSampleBean().getMap2().get("bleh").intValue()); executeSetExpression(s, foo, new Integer(12)); assertEquals(12, foo.getSampleBean().getMap2().get("bleh").intValue()); }
public void testSetProperty() { Foo foo = new Foo(); Map context = Ognl.createDefaultContext(foo); assertFalse(123456 == foo.getNumber()); ognlUtil.setProperty("number", "123456", foo, context); assertEquals(123456, foo.getNumber()); }
@Test public void testOrderByRawArg() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo1 = new Foo(); foo1.val = 1; assertEquals(1, dao.create(foo1)); Foo foo2 = new Foo(); foo2.val = 2; assertEquals(1, dao.create(foo2)); List<Foo> results = dao.queryBuilder() .orderByRaw( "(" + Foo.VAL_COLUMN_NAME + " = ? ) DESC", new SelectArg(SqlType.INTEGER, 2)) .query(); assertEquals(2, results.size()); assertEquals(foo2.id, results.get(0).id); assertEquals(foo1.id, results.get(1).id); results = dao.queryBuilder() .orderByRaw("(" + Foo.VAL_COLUMN_NAME + " = ? )", new SelectArg(SqlType.INTEGER, 2)) .query(); assertEquals(2, results.size()); assertEquals(foo1.id, results.get(0).id); assertEquals(foo2.id, results.get(1).id); }
public void run() { if (firstMethod.equals("A")) { foo.methodA(name); } else { foo.methodB(name); } }
@Test public void testCountOf() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); assertEquals(0, qb.countOf()); Foo foo1 = new Foo(); int val = 123213; foo1.val = val; assertEquals(1, dao.create(foo1)); assertEquals(1, qb.countOf()); Foo foo2 = new Foo(); foo2.val = val; assertEquals(1, dao.create(foo2)); assertEquals(2, qb.countOf()); String distinct = "DISTINCT(" + Foo.VAL_COLUMN_NAME + ")"; assertEquals(1, qb.countOf(distinct)); qb.setCountOf(distinct); assertEquals(1, dao.countOf(qb.prepare())); distinct = "DISTINCT(" + Foo.ID_COLUMN_NAME + ")"; assertEquals(2, qb.countOf(distinct)); qb.setCountOf(distinct); assertEquals(2, dao.countOf(qb.prepare())); }
@Test public void testUtf8() throws Exception { Dao<Foo, Integer> dao = createDao(Foo.class, true); Foo foo = new Foo(); foo.stringField = "اعصاب"; assertEquals(1, dao.create(foo)); QueryBuilder<Foo, Integer> qb = dao.queryBuilder(); List<Foo> results = qb.where().like(Foo.STRING_COLUMN_NAME, '%' + foo.stringField + '%').query(); assertNotNull(results); assertEquals(1, results.size()); assertEquals(foo.id, results.get(0).id); assertEquals(foo.stringField, results.get(0).stringField); qb.reset(); results = qb.where().like(Foo.STRING_COLUMN_NAME, new SelectArg('%' + foo.stringField + '%')).query(); assertNotNull(results); assertEquals(1, results.size()); assertEquals(foo.id, results.get(0).id); assertEquals(foo.stringField, results.get(0).stringField); }
@Test public void shouldVerifyWithNullVarArgArray() { Foo foo = Mockito.mock(Foo.class); foo.varArgs((String[]) null); Mockito.verify(foo).varArgs((String[]) Mockito.anyObject()); Mockito.verify(foo).varArgs((String[]) null); }
@Test public void shouldVerifyWithAnyObject() { Foo foo = Mockito.mock(Foo.class); foo.varArgs(""); Mockito.verify(foo).varArgs((String[]) Mockito.anyObject()); Mockito.verify(foo).varArgs((String) Mockito.anyObject()); }
@Override protected Foo getControlObject() { Foo f = new Foo(); f.theValue = 10; f.theOtherValue = 20; return f; }
public static void main(String argv[]) { director_basic_MyFoo a = new director_basic_MyFoo(); if (!a.ping().equals("director_basic_MyFoo::ping()")) { throw new RuntimeException("a.ping()"); } if (!a.pong().equals("Foo::pong();director_basic_MyFoo::ping()")) { throw new RuntimeException("a.pong()"); } Foo b = new Foo(); if (!b.ping().equals("Foo::ping()")) { throw new RuntimeException("b.ping()"); } if (!b.pong().equals("Foo::pong();Foo::ping()")) { throw new RuntimeException("b.pong()"); } A1 a1 = new A1(1, false); a1.delete(); }
@Test public void testQueryForForeign() throws Exception { Dao<Foo, Integer> fooDao = createDao(Foo.class, true); Dao<Foreign, Object> foreignDao = createDao(Foreign.class, true); Foo foo = new Foo(); foo.val = 1231; assertEquals(1, fooDao.create(foo)); Foreign foreign = new Foreign(); foreign.foo = foo; assertEquals(1, foreignDao.create(foreign)); // use the auto-extract method to extract by id List<Foreign> results = foreignDao.queryBuilder().where().eq(Foreign.FOO_COLUMN_NAME, foo).query(); assertEquals(1, results.size()); assertEquals(foreign.id, results.get(0).id); // query for the id directly List<Foreign> results2 = foreignDao.queryBuilder().where().eq(Foreign.FOO_COLUMN_NAME, foo.id).query(); assertEquals(1, results2.size()); assertEquals(foreign.id, results2.get(0).id); }
/** * Tests the serialization of a {@link CancelRequest}. * * @throws Exception test failed */ @Test public void testCancelRequest() throws Exception { final Mmi mmi = new Mmi(); final CancelRequest request = new CancelRequest(); mmi.setCancelRequest(request); request.setRequestId("request1"); request.setSource("source1"); request.setTarget("target1"); request.setContext("context1"); List<Object> data = new ArrayList<Object>(); final Bar bar = new Bar(); bar.setValue("hurz"); final Foo foo = new Foo(); final AnyComplexType any = new AnyComplexType(); // List<Object> bars = new ArrayList<Object>(); any.addContent(bar); foo.setBars(any); foo.setValue("lamm"); data.add(foo); request.setData(any); final JAXBContext ctx = JAXBContext.newInstance(Mmi.class, Foo.class, Bar.class); final Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(mmi, System.out); // marshaller.marshal(foo, System.out); }
@Test( description = "A simple test to check session replication, doesn't carefully check if a bean ids are correct") public void testSimpleSessionReplication() throws Exception { TestContainer container1 = bootstrapContainer(1, Collections.singletonList(Foo.class)); BeanManagerImpl beanManager1 = getBeanManager(container1); Bean<?> fooBean1 = beanManager1.resolve(beanManager1.getBeans(Foo.class)); TestContainer container2 = bootstrapContainer(2, Collections.singletonList(Foo.class)); BeanManagerImpl beanManager2 = getBeanManager(container2); Bean<?> fooBean2 = beanManager2.resolve(beanManager2.getBeans(Foo.class)); use(1); // Set a value into Foo1 Foo foo1 = (Foo) beanManager1.getReference( fooBean1, Foo.class, beanManager1.createCreationalContext(fooBean1)); foo1.setName("container 1"); replicateSession(1, container1, 2, container2); use(2); Foo foo2 = (Foo) beanManager2.getReference( fooBean2, Foo.class, beanManager2.createCreationalContext(fooBean2)); assert foo2.getName().equals("container 1"); use(2); container2.stopContainer(); use(1); container1.stopContainer(); }
@Test public void profileStaticSend() { Foo f = new Foo(); for (int i = 0; i < MAX_RUNS; i++) { f.foo("s"); f.bar("p"); } }
@Test public void testFooBundle_en() throws Exception { // Load the bundle with the check flags enabled. // this will throw an exception if there is an error // with either the abstract Class or the properties file Foo foo = BundleMaker.load(Foo.class, Locale.UK, new DefaultBundleConfiguration()); assertNotNull(foo.bar()); }
public static void doSomething() { class Foo { void foo() {} } Foo foo = new Foo(); foo.foo(); }
/** issue #1265 */ @Test public void testUnsharedJavaSerialization() { SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(false).build(); Data data = ss.toData(new Foo()); Foo foo = ss.toObject(data); Assert.assertFalse("Objects should not be identical!", foo == foo.getBar().getFoo()); }
/** issue #1265 */ @Test public void testSharedJavaSerialization() { SerializationService ss = new DefaultSerializationServiceBuilder().setEnableSharedObject(true).build(); Data data = ss.toData(new Foo()); Foo foo = (Foo) ss.toObject(data); assertTrue("Objects are not identical!", foo == foo.getBar().getFoo()); }
public void testOgnlHandlesCrapAtTheEndOfANumber() { Foo foo = new Foo(); Map<String, Object> context = Ognl.createDefaultContext(foo); Map<String, Object> props = new HashMap<String, Object>(); props.put("aLong", "123a"); ognlUtil.setProperties(props, foo, context); assertEquals(0, foo.getALong()); }
@Transactional @Test public void testRead() throws Exception { itemReader.open(new ExecutionContext()); Foo foo = itemReader.read(); assertEquals(2, foo.getId()); foo = itemReader.read(); assertEquals(3, foo.getId()); assertNull(itemReader.read()); }
public void testSetCoercion() { Serializable s = compileSetExpression("name"); Foo foo = new Foo(); executeSetExpression(s, foo, 12); assertEquals("12", foo.getName()); foo = new Foo(); setProperty(foo, "name", 12); assertEquals("12", foo.getName()); }