FieldProcessor { void processLinks(T entity, UriInfo uriInfo, ResourceMappingContext rmc, ResourceLinkContributionContext rlcc) { Set<Object> processed = new HashSet<Object>(); Object resource = uriInfo.getMatchedResources().get(0); processLinks(entity, resource, entity, processed, uriInfo, rmc, rlcc); } FieldProcessor(Class<T> c);   }
@Test public void testComputedProperty() { LOG.info("Computed property"); FieldProcessor<TestClassH> instance = new FieldProcessor(TestClassH.class); TestClassH testClass = new TestClassH(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/widgets/10", testClass.link); }
@Test public void testEL() { LOG.info("El link"); FieldProcessor<TestClassI> instance = new FieldProcessor(TestClassI.class); TestClassI testClass = new TestClassI(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/widgets/10", testClass.link); }
@Test public void testMixed() { LOG.info("Mixed EL and template vars link"); FieldProcessor<TestClassJ> instance = new FieldProcessor(TestClassJ.class); TestClassJ testClass = new TestClassJ(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/widgets/10/widget/10", testClass.link); }
@Test public void testELScopes() { LOG.info("EL scopes"); FieldProcessor<OuterBean> instance = new FieldProcessor(OuterBean.class); OuterBean testClass = new OuterBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/inner", testClass.inner.innerUri); assertEquals("/application/resources/outer", testClass.inner.outerUri); }
@Test public void testELBinding() { LOG.info("EL binding"); FieldProcessor<BoundLinkBean> instance = new FieldProcessor(BoundLinkBean.class); BoundLinkBean testClass = new BoundLinkBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/name", testClass.uri); }
@Test public void testELBindingOnLink() { LOG.info("EL binding"); FieldProcessor<BoundLinkOnLinkBean> instance = new FieldProcessor(BoundLinkOnLinkBean.class); BoundLinkOnLinkBean testClass = new BoundLinkOnLinkBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/name", testClass.link.getUri().toString()); assertEquals("self", testClass.link.getRel()); }
@Test public void testELBindingOnLinks() { LOG.info("EL binding"); FieldProcessor<BoundLinkOnLinksBean> instance = new FieldProcessor(BoundLinkOnLinksBean.class); BoundLinkOnLinksBean testClass = new BoundLinkOnLinksBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/name", testClass.links.get(0).getUri().toString()); assertEquals("self", testClass.links.get(0).getRel()); assertEquals("other", testClass.links.get(1).getRel()); assertEquals("/application/resources/name", testClass.linksArray[0].getUri().toString()); assertEquals("self", testClass.linksArray[0].getRel()); assertEquals("other", testClass.linksArray[1].getRel()); }
@Test public void testCondition() { LOG.info("Condition"); FieldProcessor<ConditionalLinkBean> instance = new FieldProcessor(ConditionalLinkBean.class); ConditionalLinkBean testClass = new ConditionalLinkBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/name", testClass.uri1); assertEquals(null, testClass.uri2); }
@Test public void testSubresource() { LOG.info("Subresource"); FieldProcessor<SubResourceBean> instance = new FieldProcessor(SubResourceBean.class); SubResourceBean testClass = new SubResourceBean(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/a/b", testClass.uri); }
@Test public void testQueryResource() { LOG.info("QueryResource"); FieldProcessor<QueryResourceBean> instance = new FieldProcessor(QueryResourceBean.class); QueryResourceBean testClass = new QueryResourceBean("queryExample", null); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/a/b?query=queryExample&query2=", testClass.uri); }
@Test public void testDoubleQueryResource() { LOG.info("QueryResource"); FieldProcessor<QueryResourceBean> instance = new FieldProcessor(QueryResourceBean.class); QueryResourceBean testClass = new QueryResourceBean("queryExample", "queryExample2"); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/a/b?query=queryExample&query2=queryExample2", testClass.uri); }
@Test public void testQueryResourceWithoutBindings() { LOG.info("QueryResource"); FieldProcessor<QueryResourceBeanNoBindings> instance = new FieldProcessor(QueryResourceBeanNoBindings.class); QueryResourceBeanNoBindings testClass = new QueryResourceBeanNoBindings(); mockUriInfo.getQueryParameters().putSingle("query", "queryExample"); mockUriInfo.getQueryParameters().putSingle("query2", "queryExample2"); assertEquals("queryExample", mockUriInfo.getQueryParameters().getFirst("query")); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/a/b?query=queryExample&query2=queryExample2", testClass.uri); mockUriInfo.getQueryParameters().clear(); }
@Test public void testBeanParamResource() { LOG.info("BeanParamResource"); FieldProcessor<BeanParamResourceBean> instance = new FieldProcessor(BeanParamResourceBean.class); BeanParamResourceBean testClass = new BeanParamResourceBean("queryExample"); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("/application/resources/a/b?qparam=foo&query=queryExample", testClass.uri); }
@Test public void testKL() { final LoggingFilter lf = new LoggingFilter(); Logger.getLogger(FieldDescriptor.class.getName()).setFilter(lf); assertTrue(lf.getCount() == 0); FieldProcessor<TestClassK> instanceK = new FieldProcessor(TestClassK.class); TestClassK testClassK = new TestClassK(); instanceK.processLinks(testClassK, mockUriInfo, mockRmc, mockRlcc); assertTrue(lf.getCount() == 0); FieldProcessor<TestClassL> instanceL = new FieldProcessor(TestClassL.class); TestClassL testClassL = new TestClassL(); instanceL.processLinks(testClassL, mockUriInfo, mockRmc, mockRlcc); assertTrue(lf.getCount() == 0); Logger.getLogger(FieldDescriptor.class.getName()).setFilter(null); }
@Test public void testNoRecursiveNesting() { LOG.info("No Recursive Nesting"); FieldProcessor<TestClassM> instance = new FieldProcessor(TestClassM.class); TestClassE nested = new TestClassE("10"); TestClassE transientNested = new TestClassE("30"); TestClassM testClass = new TestClassM("20", nested, transientNested); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/20", testClass.thelink); assertEquals(null, testClass.nested.link); assertEquals(null, testClass.transientNested.link); }
@Test public void testIgnoreTransient() { TestClassN testClass = new TestClassN(); FieldProcessor<TestClassN> instance = new FieldProcessor(TestClassN.class); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); }
@Test public void testProcessLinks() { LOG.info("Links"); FieldProcessor<TestClassD> instance = new FieldProcessor(TestClassD.class); TestClassD testClass = new TestClassD(); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals(TEMPLATE_A, testClass.res1); assertEquals(TEMPLATE_A, testClass.res2.toString()); }
@Test public void testProcessLinksWithFields() { LOG.info("Links from field values"); FieldProcessor<TestClassE> instance = new FieldProcessor(TestClassE.class); TestClassE testClass = new TestClassE("10"); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/10", testClass.link); }
@Test public void testNesting() { LOG.info("Nesting"); FieldProcessor<TestClassF> instance = new FieldProcessor(TestClassF.class); TestClassE nested = new TestClassE("10"); TestClassF testClass = new TestClassF("20", nested); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/20", testClass.thelink); assertEquals("widgets/10", testClass.nested.link); }
@Test public void testArray() { LOG.info("Array"); FieldProcessor<TestClassE[]> instance = new FieldProcessor(TestClassE[].class); TestClassE item1 = new TestClassE("10"); TestClassE item2 = new TestClassE("20"); TestClassE array[] = {item1, item2}; instance.processLinks(array, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/10", array[0].link); assertEquals("widgets/20", array[1].link); }
@Test public void testCollection() { LOG.info("Collection"); FieldProcessor<List> instance = new FieldProcessor(List.class); TestClassE item1 = new TestClassE("10"); TestClassE item2 = new TestClassE("20"); List<TestClassE> list = Arrays.asList(item1, item2); instance.processLinks(list, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/10", list.get(0).link); assertEquals("widgets/20", list.get(1).link); }
@Test public void testMap() { LOG.info("Map"); FieldProcessor<Map> instance = new FieldProcessor(Map.class); TestClassE item1 = new TestClassE("10"); TestClassE item2 = new TestClassE("20"); Map<String, TestClassE> map = new HashMap<>(); for (TestClassE item : Arrays.asList(item1, item2)) { map.put(item.getId(), item); } instance.processLinks(map, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/10", map.get("10").link); assertEquals("widgets/20", map.get("20").link); }
@Test public void testLinkStyles() { LOG.info("Link styles"); FieldProcessor<TestClassG> instance = new FieldProcessor(TestClassG.class); TestClassG testClass = new TestClassG("10"); instance.processLinks(testClass, mockUriInfo, mockRmc, mockRlcc); assertEquals("widgets/10", testClass.relativePath); assertEquals("/application/resources/widgets/10", testClass.absolutePath); assertEquals("/application/resources/widgets/10", testClass.defaultStyle); assertEquals("http: }