List of usage examples for java.util Collections singletonMap
public static <K, V> Map<K, V> singletonMap(K key, V value)
From source file:org.jtalks.poulpe.web.AuthenticationCleaningAccessDeniedExceptionHandlerTest.java
@Test(dataProvider = "requestAndResponse") public void specialUrlRedirectsToAlternativeRoute(HttpServletRequest request, HttpServletResponse response) throws Exception { String currentUrl = "/login.zul"; String redirectedUrl = "/"; doReturn(currentUrl).when(request).getServletPath(); accessDeniedHandler.setAlternativeRoutes(Collections.singletonMap("/login.zul", "/")); accessDeniedHandler.handle(request, response, new AccessDeniedException("403")); verify(response).sendRedirect(CONTEXT_PATH + redirectedUrl); }
From source file:org.terasoluna.gfw.functionaltest.domain.service.date.DateServiceImpl.java
@Override public void deleteSystemDate(int id) { jdbcTemplate.update(DELETE_SYSTEM_DATE_BY_ID, Collections.singletonMap("system_date_id", new Integer(id))); }
From source file:com.elasticbox.jenkins.k8s.plugin.builders.DeployChartBuildStep.java
@Override protected void doPerform(Run<?, ?> run, TaskLogger taskLogger, KubernetesCloud kubeCloud, ChartRepo chartRepo) throws ServiceException { taskLogger.info("Deploying chart: " + getChartName()); final String namespace = kubeCloud.getNamespace(); final String runName = (run != null) ? run.toString() : "<NO-RUN>"; Map<String, String> label = Collections.singletonMap(JENKINS_JOB, StringUtils.deleteWhitespace(runName).replace('#', '_')); final Chart chart = deploymentService.deployChart(getKubeName(), namespace, chartRepo, chartName, label); taskLogger.info("Chart [" + chartName + "] deployed"); if (deleteChartWhenFinished && run instanceof FreeStyleBuild) { taskLogger.info("Chart [" + chartName + "] will be deleted at the end of the run"); final DeployChartCleanup chartCleanup = new DeployChartCleanup(this, namespace, chart, taskLogger); ((FreeStyleBuild) run).getEnvironments().add(0, chartCleanup); }/* ww w . j ava2 s.c om*/ }
From source file:de.codecentric.boot.admin.notify.filter.web.NotificationFilterController.java
@RequestMapping(path = "/api/notifications/filters", method = { RequestMethod.POST }, produces = MimeTypeUtils.APPLICATION_JSON_VALUE) public ResponseEntity<?> addFilter(@RequestParam(name = "id", required = false) String id, @RequestParam(name = "name", required = false) String name, @RequestParam(name = "ttl", required = false, defaultValue = "-1") long ttl) { if (hasText(id) || hasText(name)) { NotificationFilter filter = createFilter(id, name, ttl); String filterId = filteringNotifier.addFilter(filter); return ResponseEntity.ok(Collections.singletonMap(filterId, filter)); } else {//from w ww. j a v a2 s .com return ResponseEntity.badRequest().body("Either 'id' or 'name' must be set"); } }
From source file:net.sourceforge.vulcan.jabber.JdbcScreenNameMapperTest.java
public void testHandlesUserNotFound() throws Exception { fakeResults.put("Tara", "tara22"); assertEquals(Collections.singletonMap("Tara", "tara22"), mapper.lookupByAuthor(makeAuthorList("Sam", "Tara"))); }
From source file:org.elasticsearch.client.StoredScriptsIT.java
public void testGetStoredScript() throws Exception { final StoredScriptSource scriptSource = new StoredScriptSource("painless", "Math.log(_score * 2) + params.my_modifier", Collections.singletonMap(Script.CONTENT_TYPE_OPTION, XContentType.JSON.mediaType())); final String script = Strings.toString(scriptSource.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS)); // TODO: change to HighLevel PutStoredScriptRequest when it will be ready // so far - using low-level REST API Response putResponse = adminClient().performRequest("PUT", "/_scripts/calculate-score", emptyMap(), new StringEntity("{\"script\":" + script + "}", ContentType.APPLICATION_JSON)); assertEquals(putResponse.getStatusLine().getReasonPhrase(), 200, putResponse.getStatusLine().getStatusCode()); assertEquals("{\"acknowledged\":true}", EntityUtils.toString(putResponse.getEntity())); GetStoredScriptRequest getRequest = new GetStoredScriptRequest("calculate-score"); getRequest.masterNodeTimeout("50s"); GetStoredScriptResponse getResponse = execute(getRequest, highLevelClient()::getScript, highLevelClient()::getScriptAsync); assertThat(getResponse.getSource(), equalTo(scriptSource)); }
From source file:com.xpn.xwiki.pdf.impl.PDFURIResolverTest.java
@Test public void resolveWhenMapItemExists() throws Exception { DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); AttachmentReference attachmentReference = new AttachmentReference("fileName", documentReference); com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); XWikiDocument document = mock(XWikiDocument.class); XWikiAttachment attachment = mock(XWikiAttachment.class); XWikiContext context = mock(XWikiContext.class); // Add an encoded space character to test that the URL is not decoded. The input URL (to be resolved) is // expected to be encoded because the URL factory creates encoded URLs. String url = "encoded+url"; when(context.get("pdfExportImageURLMap")).thenReturn(Collections.singletonMap(url, attachmentReference)); when(context.getWiki()).thenReturn(xwiki); when(xwiki.getDocument(attachmentReference.extractReference(EntityType.DOCUMENT), context)) .thenReturn(document);//from www. j ava 2s. c o m when(document.getAttachment("fileName")).thenReturn(attachment); when(attachment.getContentInputStream(context)).thenReturn(new ByteArrayInputStream("content".getBytes())); PDFURIResolver resolver = new PDFURIResolver(context); Source source = resolver.resolve(url, "base"); Assert.assertEquals(StreamSource.class, source.getClass()); Assert.assertEquals("content", IOUtils.readLines(((StreamSource) source).getInputStream()).get(0)); }
From source file:marshalsec.Red5AMFBase.java
@Override @Args(minArgs = 1, args = { "jndiUrl" }, defaultArgs = { MarshallerBase.defaultJNDIUrl }) public Object makePropertyPathFactory(UtilFactory uf, String[] args) throws Exception { String jndiUrl = args[0];//from ww w .ja va 2s . c o m PropertyInjectingProxy bfproxy = new PropertyInjectingProxy(new SimpleJndiBeanFactory(), Collections.singletonMap("shareableResources", new String[] { jndiUrl })); // RED5 uses a regular HashMap to temporarily store the property values // // To make sure the property setters are called in the right order we // have to make sure that they end up in bins matching that order Map<String, Object> values = new LinkedHashMap<>(); int size = 16; for (; size < Short.MAX_VALUE; size = size << 1) { long p = mapHash("propertyPath".hashCode() & 0xFFFFFFFFL) % size; long t = mapHash("targetBeanName".hashCode() & 0xFFFFFFFFL) % size; long b = mapHash("beanFactory".hashCode() & 0xFFFFFFFFL) % size; if (p <= b && t <= b) { System.err.println( String.format("propertyPath @ %d targetBeanName @ %d beanFactory @ %d with table size %d", p, t, b, size)); break; } } values.put("propertyPath", "a"); values.put("targetBeanName", jndiUrl); values.put("beanFactory", bfproxy); // this blows up the table to the desired size // keys must be distributed more or less evenly or the hash table won't expand to the desired size for (int j = 0; j < size / 2; j++) { values.put("" + j, ""); } return new PropertyInjectingProxy(new PropertyPathFactoryBean(), values); }
From source file:org.commonjava.aprox.depgraph.rest.ProjectController.java
public String errors(final String groupId, final String artifactId, final String version, final String workspaceId) throws AproxWorkflowException { final ProjectVersionRef ref = new ProjectVersionRef(groupId, artifactId, version); final ViewParams params = new ViewParams(workspaceId, ref); try {/*from w w w. ja va2 s. com*/ final String error = ops.getProjectError(ref, params); if (error == null) { return null; } return serializer.writeValueAsString(Collections.singletonMap("items", Collections.singleton(error))); } catch (final CartoDataException e) { throw new AproxWorkflowException("Failed to lookup errors for: {} in: {}. Reason: {}", e, ref == null ? "all projects" : ref, params, e.getMessage()); } catch (final JsonProcessingException e) { throw new AproxWorkflowException("Failed to serialize to JSON: %s", e, e.getMessage()); } }
From source file:io.fabric8.maven.enricher.standard.VolumePermissionEnricherTest.java
@Test public void alreadyExistingInitContainer(@Mocked final ProcessorConfig config) throws Exception { new Expectations() { {/*from w w w. jav a 2 s .co m*/ context.getConfig(); result = config; } }; PodTemplateBuilder ptb = createEmptyPodTemplate(); addVolume(ptb, "VolumeA"); JSONArray initContainers = new JSONArray(); JSONObject initContainer = new JSONObject(); initContainer.put("name", VolumePermissionEnricher.ENRICHER_NAME); initContainer.put("mountPath", "blub"); initContainers.put(initContainer); ptb.editTemplate().editMetadata().withAnnotations( Collections.singletonMap(InitContainerHandler.INIT_CONTAINER_ANNOTATION, initContainers.toString())) .endMetadata().endTemplate(); KubernetesListBuilder klb = new KubernetesListBuilder().addToPodTemplateItems(ptb.build()); VolumePermissionEnricher enricher = new VolumePermissionEnricher(context); enricher.adapt(klb); String initS = ((PodTemplate) klb.build().getItems().get(0)).getTemplate().getMetadata().getAnnotations() .get(InitContainerHandler.INIT_CONTAINER_ANNOTATION); assertNotNull(initS); JSONArray actualInitContainers = new JSONArray(initS); assertEquals(1, actualInitContainers.length()); JSONObject actualInitContainer = actualInitContainers.getJSONObject(0); assertEquals("blub", actualInitContainer.get("mountPath")); }