RefProcessor { public void processLinks(T entity, UriInfo uriInfo) { Set<Object> processed = new HashSet<Object>(); Object resource = uriInfo.getMatchedResources().get(0); processLinks(entity, resource, entity, processed, uriInfo); } RefProcessor(Class<T> c); void processLinks(T entity, UriInfo uriInfo);  }
@Test public void testProcessLinks() { System.out.println("Links"); RefProcessor<TestClassD> instance = new RefProcessor(TestClassD.class); TestClassD testClass = new TestClassD(); instance.processLinks(testClass, mockUriInfo); assertEquals(TEMPLATE_A, testClass.res1); assertEquals(TEMPLATE_A, testClass.res2.toString()); }
@Test public void testProcessLinksWithFields() { System.out.println("Links from field values"); RefProcessor<TestClassE> instance = new RefProcessor(TestClassE.class); TestClassE testClass = new TestClassE("10"); instance.processLinks(testClass, mockUriInfo); assertEquals("widgets/10", testClass.link); }
@Test public void testNesting() { System.out.println("Nesting"); RefProcessor<TestClassF> instance = new RefProcessor(TestClassF.class); TestClassE nested = new TestClassE("10"); TestClassF testClass = new TestClassF("20", nested); instance.processLinks(testClass, mockUriInfo); assertEquals("widgets/20", testClass.thelink); assertEquals("widgets/10", testClass.nested.link); }
@Test public void testArray() { System.out.println("Array"); RefProcessor<TestClassE[]> instance = new RefProcessor(TestClassE[].class); TestClassE item1 = new TestClassE("10"); TestClassE item2 = new TestClassE("20"); TestClassE array[] = {item1, item2}; instance.processLinks(array, mockUriInfo); assertEquals("widgets/10", array[0].link); assertEquals("widgets/20", array[1].link); }
@Test public void testCollection() { System.out.println("Collection"); RefProcessor<List> instance = new RefProcessor(List.class); TestClassE item1 = new TestClassE("10"); TestClassE item2 = new TestClassE("20"); List<TestClassE> list = Arrays.asList(item1, item2); instance.processLinks(list, mockUriInfo); assertEquals("widgets/10", list.get(0).link); assertEquals("widgets/20", list.get(1).link); }
@Test public void testLinkStyles() { System.out.println("Link styles"); RefProcessor<TestClassG> instance = new RefProcessor(TestClassG.class); TestClassG testClass = new TestClassG("10"); instance.processLinks(testClass, mockUriInfo); assertEquals("widgets/10", testClass.relativePath); assertEquals("/application/resources/widgets/10", testClass.absolutePath); assertEquals("/application/resources/widgets/10", testClass.defaultStyle); assertEquals("http: }
@Test public void testComputedProperty() { System.out.println("Computed property"); RefProcessor<TestClassH> instance = new RefProcessor(TestClassH.class); TestClassH testClass = new TestClassH(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/widgets/10", testClass.link); }
@Test public void testEL() { System.out.println("EL link"); RefProcessor<TestClassI> instance = new RefProcessor(TestClassI.class); TestClassI testClass = new TestClassI(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/widgets/10", testClass.link); }
@Test public void testMixed() { System.out.println("Mixed EL and template vars link"); RefProcessor<TestClassJ> instance = new RefProcessor(TestClassJ.class); TestClassJ testClass = new TestClassJ(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/widgets/10/widget/10", testClass.link); }
@Test public void testELScopes() { System.out.println("EL scopes"); RefProcessor<OuterBean> instance = new RefProcessor(OuterBean.class); OuterBean testClass = new OuterBean(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/inner", testClass.inner.innerUri); assertEquals("/application/resources/outer", testClass.inner.outerUri); }
@Test public void testELBinding() { System.out.println("EL binding"); RefProcessor<BoundLinkBean> instance = new RefProcessor(BoundLinkBean.class); BoundLinkBean testClass = new BoundLinkBean(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/name", testClass.uri); }
@Test public void testCondition() { System.out.println("Condition"); RefProcessor<ConditionalLinkBean> instance = new RefProcessor(ConditionalLinkBean.class); ConditionalLinkBean testClass = new ConditionalLinkBean(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/name", testClass.uri1); assertEquals(null, testClass.uri2); }
@Test public void testSubresource() { System.out.println("Subresource"); RefProcessor<SubResourceBean> instance = new RefProcessor(SubResourceBean.class); SubResourceBean testClass = new SubResourceBean(); instance.processLinks(testClass, mockUriInfo); assertEquals("/application/resources/a/b", testClass.uri); }
@Test public void testKL() { final LoggingFilter lf = new LoggingFilter(); Logger.getLogger(FieldDescriptor.class.getName()).setFilter(lf); assertTrue(lf.getCount() == 0); RefProcessor<TestClassK> instanceK = new RefProcessor(TestClassK.class); TestClassK testClassK = new TestClassK(); instanceK.processLinks(testClassK, mockUriInfo); assertTrue(lf.getCount() == 0); RefProcessor<TestClassL> instanceL = new RefProcessor(TestClassL.class); TestClassL testClassL = new TestClassL(); instanceL.processLinks(testClassL, mockUriInfo); assertTrue(lf.getCount() == 0); Logger.getLogger(FieldDescriptor.class.getName()).setFilter(null); }