### Question:
TemplateResource extends ResourceBase { @GET @Path("/template") @Produces({LD_JSON + UTF_8, JSON + UTF_8}) public final Response getTemplateForResourceType(@PathParam("type") String type, @Context UriInfo uriInfo) { Map<String, String> queryParameters = uriInfo .getQueryParameters() .entrySet() .stream() .collect(toMap(Entry::getKey, TemplateResource::firstValue)); final Model model = QueryExecutionFactory.create(SPARQL_QUERY_BUILDER.resourceTemplateQuery(type, queryParameters), MODEL).execDescribe(); UpdateAction.parseExecute(SPARQL_QUERY_BUILDER.removeTemplateMatchTriples(), model); final long count = model.listSubjects() .toList() .stream() .filter(RDFNode::isURIResource) .count(); if (count > 1) { log.warn(format("Template requested for %s with query %s resulted in %d templates.", type, uriInfo.getRequestUri().getRawQuery(), count)); } final Optional<Resource> resource = model.listSubjects().toList().stream().filter(RDFNode::isURIResource).findFirst(); return resource.map((Resource r) -> { List<Statement> statementsWithOldSubject = newArrayList(); List<Statement> statementsWithNewSubject = newArrayList(); final StmtIterator statementsAboutTheTemplate = model.listStatements(new SimpleSelector() { @Override public boolean test(Statement s) { return s.getSubject().equals(r); } }); statementsAboutTheTemplate.forEachRemaining(s -> { statementsWithOldSubject.add(s); final String regex = format("(^.*%s)\\/(.*$)", type); final String queryPart = uriInfo.getRequestUri().getRawQuery() != null ? format("?%s", uriInfo.getRequestUri().getRawQuery()) : ""; final String replacement = format("$1/template%s", queryPart); statementsWithNewSubject.add( createStatement( createResource( r.getURI().replaceAll( regex, replacement)), s.getPredicate(), s.getObject())); }); model.remove(statementsWithOldSubject); model.add(statementsWithNewSubject); return ok().entity(getJsonldCreator().asJSONLD(model)).build(); }).orElseGet(noContent()::build); } TemplateResource(); @GET @Path("/template") @Produces({LD_JSON + UTF_8, JSON + UTF_8}) final Response getTemplateForResourceType(@PathParam("type") String type, @Context UriInfo uriInfo); static final SPARQLQueryBuilder SPARQL_QUERY_BUILDER; static final Gson GSON; static final Model MODEL; }### Answer:
@Test public void should_get_204_for_unknown_template() throws Exception { templateResource = new TemplateResource(); final UriInfo uriInfo = createMockUriInfo(PUBLICATION, MEDIA_TYPE, TELEPATHIC_TRANSFER); final Response response = templateResource.getTemplateForResourceType(PUBLICATION, uriInfo); assertEquals(204, response.getStatus()); }
@Test public void should_get_204_when_no_parameters() throws Exception { templateResource = new TemplateResource(); final UriInfo uriInfo = createEmptyMockUriInfo(WORK); final Response response = templateResource.getTemplateForResourceType(WORK, uriInfo); assertEquals(204, response.getStatus()); }