List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:com.adobe.acs.commons.oak.impl.EnsureOakIndexJobHandler.java
@Override @SuppressWarnings("squid:S1141") public void run() { ResourceResolver resourceResolver = null; try {/*from www.jav a 2s .c om*/ Map<String, Object> authInfo = Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_NAME); resourceResolver = this.ensureOakIndex.getResourceResolverFactory() .getServiceResourceResolver(authInfo); try { this.ensure(resourceResolver, ensureDefinitionsPath, oakIndexesPath); } catch (IOException e) { log.error("Could not ensure management of Oak Index [ {} ]", oakIndexesPath, e); } } catch (IllegalArgumentException e) { log.error("Could not ensure oak indexes due to illegal arguments.", e); } catch (LoginException e) { log.error("Could not get an admin resource resolver to ensure Oak Indexes", e); } catch (Exception e) { log.error("Unknown error occurred while ensuring indexes", e); } finally { if (resourceResolver != null) { resourceResolver.close(); } } }
From source file:org.cloudfoundry.identity.uaa.security.web.UaaRequestMatcherTests.java
@Test public void pathMatcherMatchesExpectedPathsAndEmptyParameters() throws Exception { // Accept only JSON UaaRequestMatcher matcher = new UaaRequestMatcher("/somePath"); matcher.setAccept(Arrays.asList(MediaType.APPLICATION_JSON.toString())); matcher.setParameters(Collections.singletonMap("code", "")); assertTrue(matcher.matches(request("/somePath", null, "code", "FOO"))); assertFalse(matcher.matches(request("/somePath", null))); }
From source file:com.adobe.acs.commons.wcm.impl.DynamicClassicUiClientLibraryServletTest.java
@Test public void testCustom() throws Exception { servlet.activate(Collections.singletonMap("categories", new String[] { CUSTOM.id })); servlet.doGet(request, response);//from ww w. j a va 2 s .c o m JSONAssert.assertEquals("{'js':['/etc/clientlibs/custom.js'], 'css':['/etc/clientlibs/custom.css']}", writer.toString(), false); }
From source file:org.kitodo.data.elasticsearch.KitodoRestClient.java
/** * Get mapping./* w w w.j ava 2s. c o m*/ * * @return mapping */ public String getMapping() throws IOException { Response response = client.performRequest(HttpMethod.GET, "/" + index + "/_mapping", Collections.singletonMap("pretty", "true")); return EntityUtils.toString(response.getEntity()); }
From source file:com.kinesis.datavis.servlet.GetBidRqCountsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;// w ww.jav a 2 s . co m } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); } DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>(); BidRequestCount hashKey = new BidRequestCount(); hashKey.setHashKey(Ticker.getInstance().hashKey()); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); // Condition attrFilter = // new Condition(). // withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource)); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); // query.setQueryFilter(Collections.singletonMap("wh", attrFilter)); List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query); // System.out.println(counts.size()); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:com.liveramp.cascading_ext.CascadingUtil.java
private Map<String, String> getSerializationTokensProperty() { List<String> strings = new ArrayList<String>(); for (Map.Entry<Integer, Class<?>> entry : serializationTokens.entrySet()) { strings.add(entry.getKey() + "=" + entry.getValue().getName()); }//from w w w. ja va 2 s . c o m if (strings.isEmpty()) { return Collections.emptyMap(); } else { return Collections.singletonMap("cascading.serialization.tokens", StringUtils.join(strings, ",")); } }
From source file:de.hybris.platform.b2bacceleratorfacades.order.impl.DefaultB2BCheckoutFacadeIntegrationTest.java
@Before public void beforeTest() throws Exception { createCoreData();//from w w w .j a va 2 s .c o m createDefaultCatalog(); importCsv("/b2bacceleratorfacades/test/testOrganizations.csv", "utf-8"); importCsv("/b2bacceleratorfacades/test/testB2BCommerceCart.csv", "utf-8"); baseSiteService.setCurrentBaseSite(baseSiteService.getBaseSiteForUID("b2bstoretemplate"), false); final CartModel modelByExample = new CartModel(); modelByExample.setCode("dc_shhCart_b2baf"); final CartModel cart = flexibleSearchService.getModelByExample(modelByExample); Assert.assertNotNull("dc_shhCart_b2baf cart.code should have been found", cart); cartService.setSessionCart(cart); userService.setCurrentUser(cart.getUser()); if (flexibleSearchService .search("SELECT {" + ServicelayerJobModel.PK + "} FROM {" + ServicelayerJobModel._TYPECODE + "} WHERE " + "{" + ServicelayerJobModel.SPRINGID + "}=?springid", Collections.singletonMap("springid", "b2bAcceleratorCartToOrderJob")) .getResult().isEmpty()) { final ServicelayerJobModel servicelayerJobModel = modelService.create(ServicelayerJobModel.class); servicelayerJobModel.setCode("b2bAcceleratorCartToOrderJob"); servicelayerJobModel.setSpringId("b2bAcceleratorCartToOrderJob"); modelService.save(servicelayerJobModel); } // inject a mock payment provider cardPaymentService.setCommandFactoryRegistry(mockupCommandFactoryRegistry); paymentService.setCardPaymentService(cardPaymentService); commerceCheckoutService.setPaymentService(paymentService); commerceCheckoutService.setBaseSiteService(baseSiteService); }
From source file:com.erudika.scoold.controllers.AdminController.java
@PostMapping("/add-space") public String addSpace(@RequestParam String space, HttpServletRequest req, HttpServletResponse res, Model model) {/*from ww w.j ava 2s.co m*/ Profile authUser = utils.getAuthUser(req); if (!StringUtils.isBlank(space) && utils.isAdmin(authUser)) { space = Utils.abbreviate(space, 255); String spaceId = Utils.noSpaces(Utils.stripAndTrim(space, " "), "-"); if ("default".equalsIgnoreCase(space) || pc.getCount("scooldspace") >= MAX_SPACES || pc.read("scooldspace:" + spaceId) != null) { if (utils.isAjaxRequest(req)) { res.setStatus(400); return "space"; } else { return "redirect:" + ADMINLINK + "?code=7&error=true"; } } else { space = space.replaceAll(":", ""); Sysprop s = new Sysprop("scooldspace:" + Utils.noSpaces(Utils.stripAndTrim(space, " "), "-")); s.setType("scooldspace"); s.setName(space); pc.create(s); authUser.getSpaces().add(s.getId() + ":" + space); authUser.update(); model.addAttribute("space", s); } } else { model.addAttribute("error", Collections.singletonMap("name", utils.getLang(req).get("requiredfield"))); } if (utils.isAjaxRequest(req)) { res.setStatus(200); return "space"; } else { return "redirect:" + ADMINLINK; } }
From source file:com.arrow.acn.client.api.DeviceStateApi.java
public StatusModel transFailed(String deviceHid, String transHid, String error) { String method = "transError"; try {/*from ww w. ja v a 2 s.c om*/ URI uri = buildUri(String.format(TRANS_FAILED_URL, deviceHid, transHid)); StatusModel result = execute(new HttpPut(uri), JsonUtils.toJson(Collections.singletonMap("error", AcsUtils.trimToEmpty(error))), StatusModel.class); log(method, result); return result; } catch (Throwable e) { logError(method, e); throw new AcnClientException(method, e); } }
From source file:com.smartitengineering.cms.spi.impl.content.JavascriptGeneratorTest.java
@Test public void testJavascriptRepGeneration() throws IOException { TypeRepresentationGenerator generator = new JavascriptRepresentationGenerator(); final RepresentationTemplate template = mockery.mock(RepresentationTemplate.class); WorkspaceAPIImpl impl = new WorkspaceAPIImpl() { @Override/*from w w w. j a v a 2s. c om*/ public RepresentationTemplate getRepresentationTemplate(WorkspaceId id, String name) { return template; } }; impl.setRepresentationGenerators(Collections.singletonMap(TemplateType.JAVASCRIPT, generator)); RepresentationProvider provider = new RepresentationProviderImpl(); final WorkspaceAPI api = impl; registerBeanFactory(api); final Content content = mockery.mock(Content.class); final Field field = mockery.mock(Field.class); final FieldValue value = mockery.mock(FieldValue.class); final Map<String, Field> fieldMap = mockery.mock(Map.class); final ContentType type = mockery.mock(ContentType.class); final Map<String, RepresentationDef> reps = mockery.mock(Map.class, "repMap"); final RepresentationDef def = mockery.mock(RepresentationDef.class); mockery.checking(new Expectations() { { exactly(1).of(template).getTemplateType(); will(returnValue(TemplateType.JAVASCRIPT)); exactly(1).of(template).getTemplate(); will(returnValue(IOUtils.toByteArray( getClass().getClassLoader().getResourceAsStream("scripts/js/test-script.js")))); exactly(1).of(template).getName(); will(returnValue(REP_NAME)); exactly(1).of(value).getValue(); will(returnValue(CONTENT)); exactly(1).of(field).getValue(); will(returnValue(value)); exactly(1).of(fieldMap).get(with(Expectations.<String>anything())); will(returnValue(field)); exactly(1).of(content).getFields(); will(returnValue(fieldMap)); exactly(1).of(content).getContentDefinition(); will(returnValue(type)); final ContentId contentId = mockery.mock(ContentId.class); exactly(2).of(content).getContentId(); will(returnValue(contentId)); final WorkspaceId wId = mockery.mock(WorkspaceId.class); exactly(1).of(contentId).getWorkspaceId(); will(returnValue(wId)); exactly(2).of(type).getRepresentationDefs(); will(returnValue(reps)); exactly(2).of(reps).get(with(REP_NAME)); will(returnValue(def)); exactly(1).of(def).getParameters(); will(returnValue(Collections.emptyMap())); exactly(1).of(def).getMIMEType(); will(returnValue(GroovyGeneratorTest.MIME_TYPE)); final ResourceUri rUri = mockery.mock(ResourceUri.class); exactly(1).of(def).getResourceUri(); will(returnValue(rUri)); exactly(1).of(rUri).getValue(); will(returnValue("iUri")); } }); Assert.assertNotNull(SmartContentAPI.getInstance()); Assert.assertNotNull(SmartContentAPI.getInstance().getContentLoader()); Representation representation = provider.getRepresentation(REP_NAME, type, content); Assert.assertNotNull(representation); Assert.assertEquals(REP_NAME, representation.getName()); Assert.assertEquals(CONTENT, StringUtils.newStringUtf8(representation.getRepresentation())); Assert.assertEquals(GroovyGeneratorTest.MIME_TYPE, representation.getMimeType()); }