public void testInverseOwnerOneToMany() { OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager(); startTx(em); AnnoTest1 pc = new AnnoTest1(5); AnnoTest2 pc2 = new AnnoTest2(15, "foo"); pc.getInverseOwnerOneMany().add(pc2); pc2.setOneManyOwner(pc); pc2 = new AnnoTest2(20, "foobar"); pc.getInverseOwnerOneMany().add(pc2); pc2.setOneManyOwner(pc); em.persist(pc); em.persistAll(pc.getInverseOwnerOneMany()); endTx(em); endEm(em); em = (OpenJPAEntityManager) currentEntityManager(); pc = em.find(AnnoTest1.class, em.getObjectId(pc)); Collection<AnnoTest2> many = pc.getInverseOwnerOneMany(); assertEquals(2, many.size()); for (AnnoTest2 pc3 : many) { assertEquals(pc, pc3.getOneManyOwner()); switch ((int) pc3.getPk1()) { case 15: assertEquals("foo", pc3.getPk2()); break; case 20: assertEquals("foobar", pc3.getPk2()); break; default: fail("unknown element:" + pc3.getPk1()); } } endEm(em); }
/** Check if the getSubBuilders properly predicts the output. */ public static void testSubBuilders() throws Exception { Workspace ws = Workspace.getWorkspace(new File("test/ws")); Project project = ws.getProject("p4-sub"); Collection<? extends Builder> bs = project.getSubBuilders(); assertNotNull(bs); assertEquals(3, bs.size()); Set<String> names = new HashSet<String>(); for (Builder b : bs) { names.add(b.getBsn()); } assertTrue(names.contains("p4-sub.a")); assertTrue(names.contains("p4-sub.b")); assertTrue(names.contains("p4-sub.c")); File[] files = project.build(); assertTrue(project.check()); System.err.println(Processor.join(project.getErrors(), "\n")); System.err.println(Processor.join(project.getWarnings(), "\n")); assertEquals(0, project.getErrors().size()); assertEquals(0, project.getWarnings().size()); assertNotNull(files); assertEquals(3, files.length); for (File file : files) { Jar jar = new Jar(file); Manifest m = jar.getManifest(); assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName"))); } }
/** Checks that sync has exactly the given queued threads. */ void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) { Collection<Thread> actual = sync.getQueuedThreads(); assertEquals(expected.length > 0, sync.hasQueuedThreads()); assertEquals(expected.length, sync.getQueueLength()); assertEquals(expected.length, actual.size()); assertEquals(expected.length == 0, actual.isEmpty()); assertEquals(new HashSet<Thread>(actual), new HashSet<Thread>(Arrays.asList(expected))); }
private static Project testBuildAll(String dependsOn, int count) throws Exception { Workspace ws = new Workspace(new File("test/ws")); Project all = ws.getProject("build-all"); all.setProperty("-dependson", dependsOn); all.prepare(); Collection<Project> dependson = all.getDependson(); assertEquals(count, dependson.size()); return all; }
/** values collection contains all values */ public void testDescendingValues() { ConcurrentNavigableMap map = dmap5(); Collection s = map.values(); assertEquals(5, s.size()); assertTrue(s.contains("A")); assertTrue(s.contains("B")); assertTrue(s.contains("C")); assertTrue(s.contains("D")); assertTrue(s.contains("E")); }
/** Duplicates in runbundles gave a bad error, should be ignored */ public static void testRunbundleDuplicates() throws Exception { Workspace ws = new Workspace(new File("test/ws")); Project top = ws.getProject("p1"); top.clear(); top.setProperty("-runbundles", "org.apache.felix.configadmin,org.apache.felix.configadmin"); Collection<Container> runbundles = top.getRunbundles(); assertTrue(top.check("Multiple bundles with the same final URL")); assertNotNull(runbundles); assertEquals(1, runbundles.size()); }
private static void assertEqualList(List<?> a, Collection<?> b) { if (a.size() == b.size()) { for (Object x : a) { if (!b.contains(x)) throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">"); } return; } throw new AssertionFailedError("expected:<" + a + "> but was: <" + b + ">"); }
/** Test 2 equal bsns but diff. versions */ public static void testSameBsnRunBundles() throws Exception { Workspace ws = new Workspace(new File("test/ws")); Project top = ws.getProject("p1"); top.setProperty( "-runbundles", "org.apache.felix.configadmin;version='[1.0.1,1.0.1]',org.apache.felix.configadmin;version='[1.1.0,1.1.0]'"); Collection<Container> runbundles = top.getRunbundles(); assertTrue(top.check()); assertNotNull(runbundles); assertEquals(2, runbundles.size()); }
/** Test bnd.bnd of project `foo`: `-runbundles: foo;version=latest` */ public static void testRunBundlesContainsSelf() throws Exception { Workspace ws = new Workspace(new File("test/ws")); Project top = ws.getProject("p1"); top.setProperty("-runbundles", "p1;version=latest"); top.setChanged(); top.isStale(); Collection<Container> runbundles = top.getRunbundles(); assertTrue(top.check("Circular dependency")); assertNotNull(runbundles); assertEquals(0, runbundles.size()); }