HeaderProcessor { List<String> getLinkHeaderValues(Object entity, UriInfo uriInfo, ResourceMappingContext rmc) { final List<Object> matchedResources = uriInfo.getMatchedResources(); if (!matchedResources.isEmpty()) { final Object resource = matchedResources.get(0); final List<String> headerValues = new ArrayList<>(); for (LinkHeaderDescriptor desc : instanceDescriptor.getLinkHeaders()) { if (ELLinkBuilder.evaluateCondition(desc.getCondition(), entity, resource, entity)) { String headerValue = getLinkHeaderValue(desc, entity, resource, uriInfo, rmc); headerValues.add(headerValue); } } return headerValues; } return Collections.emptyList(); } HeaderProcessor(Class<T> c);   }
@Test public void testLiteral() { System.out.println("Literal"); HeaderProcessor<EntityA> instance = new HeaderProcessor(EntityA.class); EntityA testClass = new EntityA(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(1, headerValues.size()); String headerValue = headerValues.get(0); assertEquals("</application/resources/A>", headerValue); }
@Test public void testEL() { System.out.println("EL"); HeaderProcessor<EntityB> instance = new HeaderProcessor(EntityB.class); EntityB testClass = new EntityB(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(1, headerValues.size()); String headerValue = headerValues.get(0); assertEquals("</application/resources/B>", headerValue); }
@Test public void testTemplateLiteral() { System.out.println("Template Literal"); HeaderProcessor<EntityC> instance = new HeaderProcessor(EntityC.class); EntityC testClass = new EntityC(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(1, headerValues.size()); String headerValue = headerValues.get(0); assertEquals("</application/resources/C>", headerValue); }
@Test public void testMultiple() { System.out.println("Multiple Literal"); HeaderProcessor<EntityD> instance = new HeaderProcessor(EntityD.class); EntityD testClass = new EntityD(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(2, headerValues.size()); String headerValue = headerValues.get(0); assertEquals("</application/resources/A>", headerValue); headerValue = headerValues.get(1); assertEquals("</application/resources/B>", headerValue); }
@Test public void testParameters() { System.out.println("Parameters"); HeaderProcessor<EntityE> instance = new HeaderProcessor(EntityE.class); EntityE testClass = new EntityE(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(1, headerValues.size()); String headerValue = headerValues.get(0); assertTrue(headerValue.contains("</application/resources/E>")); assertTrue(headerValue.contains("; rel=\"relE\"")); assertTrue(headerValue.contains("; rev=\"revE\"")); assertTrue(headerValue.contains("; type=\"type/e\"")); assertTrue(headerValue.contains("; title=\"titleE\"")); assertTrue(headerValue.contains("; anchor=\"anchorE\"")); assertTrue(headerValue.contains("; media=\"mediaE\"")); assertTrue(headerValue.contains("; hreflang=\"en-E\"")); assertTrue(headerValue.contains("; e1=\"v1\"")); assertTrue(headerValue.contains("; e2=\"v2\"")); }
@Test public void testConditional() { System.out.println("EL"); HeaderProcessor<EntityF> instance = new HeaderProcessor(EntityF.class); EntityF testClass = new EntityF(); List<String> headerValues = instance.getLinkHeaderValues(testClass, mockUriInfo, mockRmc); assertEquals(1, headerValues.size()); String headerValue = headerValues.get(0); assertEquals("</application/resources/1>", headerValue); }